Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Write Table now available in Qlik Cloud Analytics: Read Blog
cancel
Showing results for 
Search instead for 
Did you mean: 
raghavsurya
Partner - Specialist
Partner - Specialist

Defaulth "Year" getting highlighted

Hi,

We have a table called Year in which the values we have is 2009, 2010, 2011. All my expressions are designed to pick the Max year and depict the charts.

(((Sum({<Year={$(=Max(Year))}>} [Projected Sales] ))))

In the current scenario by default the data being shown is for the Max year '2011'. I have Year as list box on the tab.... the requirement here is when the sheet is opened the Max year for which the data is being shown should be hightlighted (selected) in the tab.

Can you please help me.

Thanks and Regards,

Raghav

4 Replies
Not applicable

ad this to your script (at the bottom):





MaxYearTable:
load max(Year) as MaxYearField resident Table;

//(Table: whichever table the field Year is in)

LET







vMaxYear = peek('MaxYearField', 0, 'MaxYearTable')



then, add this as a macro:





sub

set



vMax = ActiveDocument.GetVariable("vMaxYear") Max

ActiveDocument.Fields("Year"). Select vMax.GetContent. string





end







sub



and set the sub Max as a startup-macro under SETTINGS, DOCUMENT PROPERTIES, TRIGGERS, OnOpen

That should do the trick

regards

raghavsurya
Partner - Specialist
Partner - Specialist
Author

Hi,

Thanks for your valuable inputs. I have a column in one of the table which Year. I should have been more specific in my earlier posts itself.

The Columns in the table are

Cost Centre Year Stream Amount

Can you please suggest if there are any changes to the script to be made because of this.

Thanks in advance for your kind help.

Regards,

Raghav

Not applicable

Sure (sorry for all the line shifts)

If we say that the table name is "MyTable"

The script should be (remember to add it to the bottom of your script)

MaxYearTable:
load max(Year) as MaxYearField resident MyTable;

let vMaxYear = peek('MaxYearField', 0, 'MaxYearTable')

and the macro should be:

sub Max
set vMax = ActiveDocument.GetVariable("vMaxYear")
ActiveDocument.Fields("Year").Select vMax.GetContent.string
end sub

Try it, good luck 🙂

regards

raghavsurya
Partner - Specialist
Partner - Specialist
Author

Hi Jespur,

Thanks for your time mate..... I executed the all the steps but the it did'nt work for me...... not sure where I went wrong. I cud see the max value being populated in the "MaxYearField" table as well. But the same was not working when I ran the macro.

Finally I Hardcoded the value for the year 2011 in the macro

sub MaxActive

ActiveDocument.Fields("Year").Clear
ActiveDocument.Fields("Year").Select "2011"
'ActiveDocument.Fields("Year").UnLock

end sub

I know my apprach was not best practice....

Thanks and Regards,

Raghav