Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Set Analysis using variable for yearmonth expression error

Hi,

Help would be appreciated on the following.

I need to display quantities per month and also what was the quantities 2 months back in a pivot where yearmonth is my dimension.

I got it right to create a variable that contains the yearmonth as it was 2 months back but when i want to use this variable in a set analysis to display what was the quantities 2 months back it is not working ? ?





vMakeDate = AddMonths( (MakeDate( left(YearMonth,4),right(YearMonth,2))) ,-2) (this variable gives correct result)

'vCompareDate' = ($(vMakeDate),4) & mid( $(vMakeDate),6,2) (this variable gives correct result)

this is the expression that is not working:

sum( {$< FORMFLAG = {'A'},YearMonth = {$('vCompareDate')} >} Quantity ) - THIS IS MY SET ANALYSIS IN THE EXPRESION THAT IS NOT WORKING

below is the result - yellow is my yearmonth dimension and the blue is the new yearmonth - 2 months that is correct , but when is use this blue value is my vCompareDate variable . The brown is the 0 that my expression return - it seems that it 's confused about vCompareDate OR im missing something somewhere.

YEAR MONTH200911200911200911200912200912200912
=AddMonths( (MakeDate( left(YearMonth,4),right(YearMonth,2))) ,-2)2009/09/012009/09/012009/09/012009/10/012009/10/012009/10/01
=left(AddMonths( (MakeDate( left(YearMonth,4),right(YearMonth,2))) ,-2),4) & mid( AddMonths( (MakeDate( left(YearMonth,4),right(YearMonth,2))) ,-2),6,2 )200909200909200909200910200910200910
FOCUS BRANDForecast Order QuantityQuantityPREV QUANForecast Order QuantityQuantityPREV QUAN
230,629129,1830144,50683,3210
Total47,07525,08803,9812,1810
Product186001310
Product17900200
Product2146146099990
Product372720100
Product49084840100800
Product5617610017170
Product615100200
Product74200100
Product8717610015120
Product99957540109960
Product105700100
Product114400200
Product122157401760
Product131,188902082260
Product142,1901,832070600
Product151,8001,494050400
Product16226201100
Product173,1301,82202441710
Product18109980430
Product198281012110
Product205332500109880
Product2114910820
Product22100100


Regards

Louw



13 Replies
Not applicable
Author

Hi

A tricky problem with variables in set analysis is that depending on what they contain, you need to use different ways of extracting it.

I always put the dollar sign expansion in a textbox and see if I get the correct result.
In your example, the result you are after is a number and hence you should not need to use the dollar sign expansion at all but can treat the variable as a list.

sum( {$< FORMFLAG = {'A'},YearMonth = {CompareDate} >} Quantity )

Remember in set analysis, if you are assigning values to a column, multiple numeric values is written as {1,2,3,...} while string values are written as {'a','b',...} with hyphens around them.

Give it a try

partner_enginee
Partner - Contributor II
Partner - Contributor II

Sorry I'm new in QlikView.

In my script, I define vPreviousYearMonth like:

SET vPreviousYearMonth=Year(AddMonths(MakeDate(left([Year Month],4),right([Year Month],2)), -12))&'/'& Month(AddMonths(MakeDate(left([Year Month],4),right([Year Month],2)), -12));

where [Year Month] contains nel user selection of year month like 2010/02, 2010/01,2009/12.

C.

sparur
Specialist II
Specialist II

Hello,

I think you should try this expression in your chart: Count ({$<[Year Month]= {'$(vPreviousYearMonth)'}>}CMCONTRACTID)

after this you can compare one current period with this period in last year, for example 2010/02 vs 2009/02.

partner_enginee
Partner - Contributor II
Partner - Contributor II

Thanks, I resolved.

I used a new variable vListYearMonth

vListYearMonth=chr(39) & GetFieldSelections([Year Month],chr(39)&','&chr(39),1000)&chr(39)

then I make my expression like

=

count({1<[Next Year Month]={'$(vYearMonth)'}>}CMCONTRACTID)



where [Next Year Month] is a new field on my table equals to [Year Month] related to next year.

That solution is very clear.

C.