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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Reduce IF expression

I have a expression :

=if(PeriodOp='Quarter',Sum({<Quarter={$(vPriorQuarter)}>} O_TriGiaBan),if(PeriodOp='Month',Sum({<Month={$(vPriorMonth)}>} O_TriGiaBan),If(PeriodOp='Week',Sum({<WeekYear={$(vPriorWeek)}>} O_TriGiaBan))))

I wanna reduce IF expression and replace expression as follow :

=Sum({<Quarter={$(vPriorQuarter)} , Month={$(vPriorMonth)} , WeekYear={$(vPriorWeek)} >} O_TriGiaBan)


It dont work.. Quarter, Month, Week are selection...Please help me...!

Labels (1)
1 Solution

Accepted Solutions
sunny_talwar
MVP
MVP

Try changing the definiation of your variables to these:

vPriorQuarter = If(PeriodOp = 'Quarter', yourCurrentExpression, '*')

vPriorMonth = If(PeriodOp = 'Month', yourCurrentExpression, '*')

vPriorWeek = If(PeriodOp = 'Week', yourCurrentExpression, '*')


and then use this expression and see if it works:


=Sum({<Quarter={$(vPriorQuarter)} , Month={$(vPriorMonth)} , WeekYear={$(vPriorWeek)} >} O_TriGiaBan)

View solution in original post

7 Replies
gautik92
Specialist III
Specialist III

Try this =Sum({$<Quarter={$(vPriorQuarter)} , Month={$(vPriorMonth)} , WeekYear={$(vPriorWeek)} >} O_TriGiaBan)

sunny_talwar
MVP
MVP

Try changing the definiation of your variables to these:

vPriorQuarter = If(PeriodOp = 'Quarter', yourCurrentExpression, '*')

vPriorMonth = If(PeriodOp = 'Month', yourCurrentExpression, '*')

vPriorWeek = If(PeriodOp = 'Week', yourCurrentExpression, '*')


and then use this expression and see if it works:


=Sum({<Quarter={$(vPriorQuarter)} , Month={$(vPriorMonth)} , WeekYear={$(vPriorWeek)} >} O_TriGiaBan)

Not applicable
Author

It dont work @Gowtham

sunny_talwar
MVP
MVP

You might need double quotes like this:

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

Not applicable
Author

=Sum({<Quarter={$(vPriorQuarter)} , Month={$(vPriorMonth)} , WeekYear={$(vPriorWeek)} >} O_TriGiaBan)

and

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


are correct, too .

Thank you so much @Sunny T

Not applicable
Author

Hi sunindia , Can you  please make me understand clearly about this code :

vPriorQuarter = If(PeriodOp = 'Quarter', yourCurrentExpression, '*')


and when I remove '*' , this code cant work ?

sunny_talwar
MVP
MVP

This code just mean that when PeriodOp is not equal to 'Quarter' then use *. and * in set analysis means select everything.

I hope that makes sense.

Best,

Sunny