Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Help me about an epression make sense

There are  2 expression as follow :

A first expresion:

+Sum({<Quarter={"$(vPriorQuarter)"} , Month={"$(vPriorMonth)"} , WeekYear={"$(vPriorWeek)"} Date={"$(vPriorDate)"} >} Sale)

with the variable below:

-vPriorQuarter =If(PeriodOp='Quarter',Ceil(max(Month)/3)-1,'*')

-vPriorWeek =If(PeriodOp='Week',Week(Max(Date))-1,'*')

-vPriorMonth =If(PeriodOp='Month',month(addmonths(max(Date) ,- 1)),'*')

-vPriorDate ==If(PeriodOp='Date',Date(KeyDate-1,'DD/MM/YYYY'),'*')

A second expression:

+Sum({<Year=, Quarter = , Month = , WeekYear= , Date= {"$(=Date(Max(Date) -1 ))"}  >} Sale)


They get the previous data. But I check the data  and the first expression is right data, the second expression is just only  right with a date selection, and isnot perfect with  month, quarter, week selection

Can anyone please answer me the following question

Do the first or the second is the best ?? and another solution for the second expression is right with month, quarter, week selection ?

12 Replies
jagan
Luminary Alumni
Luminary Alumni

Hi,

I am not sure why you are using all variables in all date fields, if you filter by date then it is enough, no need to use vPriorQuarter, vPriorMonth, vPriorWeek, vPriorDate.

Instead of this

Sum({<Quarter={"$(vPriorQuarter)"} , Month={"$(vPriorMonth)"} , WeekYear={"$(vPriorWeek)"} Date={"$(vPriorDate)"} >} Sale)


You can simply use

Sum({<Year=, Quarter = , Month = , WeekYear= , Date= {"$(=Date(Max(Date) -1 ))"}  >} Sale).


What are the values you are having in Date field?  Is it date like 1/1/2015 or just number 1, 2, 3?


If you attach sample file then it would be easier to analyse and tell you the solution.


My expression works when Date is in date format.




sasiparupudi1
Master III
Master III

It is best to use your second expression with a date range based on your selections

previous day

Sum({<Year=, Quarter = , Month = , WeekYear= , Date= {"<=$(=Date(Max(Date))) >=$(=Date(Max(Date) -1 ))"}  >} Sale)


for previous month

Sum({<Year=, Quarter = , Month = , WeekYear= , Date= {"<=$(=Date(Max(Date))) >=$(=Date(addmonths(Max(Date) ,-1 ))"}  >} Sale)


etc

etc


hth

Sasi

Digvijay_Singh

As I understand you want to access previous 'Year or Quarter or Month or Week or Day' using single expression. It is not possible because when you subtract 1 from date, it will be a prev day only. So your 2nd expression is helping you to show one of many thing and that is to show information of previous day.

I suggest you to have Year,Quarter,Month,Week, Day field in your master calendar and achieve previous year, or Prev Quarter etc by subtracting 1 from these period fields.

I tried to put it in sample app as attached. Whatever you are doing in first option appearing the right one but you are accessing all previous period in one expression, I am not able to understand that business aspect.