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

Announcements
Qlik Connect 2026! Turn data into bold moves, April 13 -15: Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
danielnevitt
Creator
Creator

Setting Variables

Hi,

I am trying to set variables to allow us to add expressions to straight tables to show the sum of current month, previous month etc.

My column name is CONTRACT_MONTH

The variables I have set are:

vCurrMonth = =Max(CONTRACT_MONTH)

vLastMonth = =vCurrMonth-1

The above return numeric results ie vCurrMonth = 8 and vLastMonth = 7

My CONTRACT_MONTH data is in the format Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec.  I am summing this data by a column called CONTRACT_QTY.

Would it be possible for someone to advise firstly how I set the variables to the above format and secondly how I can show those results in a straight table similar to the below:

Desk          SumCurrMonth          SumLastMonth

A              

B

C

D

Any help would be much appreciated.

Regards,

Daniel

3 Replies
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

If you have a field with month numbers you could use that instead. Or create one in the script and then use it. Or you could add two helper variables to get the month names from the numbers:

vCurrMonthName: =month(makedate(1,vCurrMonth))

vLastMonthName: =month(makedate(1,vLastMonth))

SumCurrMonth: =sum({<CONTRACT_MONTH={'$(vCurrMonthName)'}>}CONTRACT_QTY)

SumLastMonth: =sum({<CONTRACT_MONTH={'$(vLastMonthName)'}>}CONTRACT_QTY)


talk is cheap, supply exceeds demand
danielnevitt
Creator
Creator
Author

Hi Gysbert,

Thank you for the reply.

The setting the MonthName works great.

Unfortunately the SumCurrMonth and SumLastMonth do not work.

The following expressions work (without variables):

sum({<CONTRACT_MONTH={`Jun`}>}CONTRACT_QTY)

sum({<CONTRACT_MONTH={`Jul`}>}CONTRACT_QTY)

Are you able to suggest how to insert the variables to the above?

Thanks

Daniel

Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

No idea. It works for me. See attached example.


talk is cheap, supply exceeds demand