Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi Guys - i am new to qlik sense - i have the same issue - i want previous month KPI to be based on filtered selection. e.g. if i select June i want previous month(May)figures to show - can someone please help ??
Hi @dching
there is many ways of doing this, you can use a master calendar by creating a column for previous month.
or the one i liked more its using variables, It may seem complicated but they are variables that every project must have
so, for current or selected month
vMaxCurrentDate = date(max(DateField))
vMinCurrentDate = monthstart(date(max(DateField)))
and for previous
vMaxPrevDate = addmonths(vMaxCurrentDate,-1)
vMinPrevDate = addmonths(vMinCurrentDate ,-1)
use the equal sign when defining the expressions
and now in your KPIs, you can set first as:
Sum({< year,month,DateField={">=$(vMinCurrentDate )<=$(vMaxCurrentDate )"} >} Sales)
and for second
Sum({< year,month,DateField={">=$(vMinPrevDate )<=$(vMaxPrevDate )"} >} Sales)
then "year,month," in the formula is to ignore the selected year and/or month and solve everything with dates
this will work when you selected a months or not.
hope it works for you.
Best,
Hi Dching,
You will likely have to use set analysis on your measure to get the previous month. Could you describe your KPI in detail? So we can help you more precisely.
Hi @dching
there is many ways of doing this, you can use a master calendar by creating a column for previous month.
or the one i liked more its using variables, It may seem complicated but they are variables that every project must have
so, for current or selected month
vMaxCurrentDate = date(max(DateField))
vMinCurrentDate = monthstart(date(max(DateField)))
and for previous
vMaxPrevDate = addmonths(vMaxCurrentDate,-1)
vMinPrevDate = addmonths(vMinCurrentDate ,-1)
use the equal sign when defining the expressions
and now in your KPIs, you can set first as:
Sum({< year,month,DateField={">=$(vMinCurrentDate )<=$(vMaxCurrentDate )"} >} Sales)
and for second
Sum({< year,month,DateField={">=$(vMinPrevDate )<=$(vMaxPrevDate )"} >} Sales)
then "year,month," in the formula is to ignore the selected year and/or month and solve everything with dates
this will work when you selected a months or not.
hope it works for you.
Best,
Hi thanks for this it works very well just that when opening the App its showing the total sales instead - wanted it to default to current month to date and previous month - is there any way to achieve this ?
Hi @dching
im glad it works for you !!!
i should be working as you need.
try to look the value of the variable in the var panel
or take a look to what the expression is doing when you dont have any selection
Best regards,
Hello!
I am using your solution, but I have a problem. Both measures seem to do not work well together.
If I put a table with DateField, Measure1 and Measure2, the second measure always return a 0.