Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Shoro
Contributor
Contributor

Set analysis - Comparison with variable

Hi,
I want to get the last month's Sum of sales.

I use a variable called vLastMonth:
= Text (Year (Today ())) & '-' & Month (AddMonths (Today (), - 1))

And this is the formula to get the Sum of last month's sales:

Sum ({$ <[Order Date.autoCalendar.YearMonth] = {"vLastMonth"}>} Sales)

But the result is: 0.
Why?

If I put "2020-Oct" it works.

Why does working with the variable fail?

I would also love to understand, why if I add $ to a variable
Sum ({$ <[Order Date.autoCalendar.YearMonth] = $ {"vLastMonth"}>} Sales)

I get the Sum of all sales without filtering of months (last month).

Thanks for your help

Labels (2)
3 Replies
Taoufiq_Zarra

@Shoro  you can try this :

=Sum ({$ <[Order Date.autoCalendar.YearMonth] = { '$(vLastMonth)' }>} Sales)

and check date format for Order Date.autoCalendar.YearMonth must be YYYY-MMM

and example :

Capture.PNG

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
Shoro
Contributor
Contributor
Author

I found that the correct formula is:
Sum ({$ <[Order Date.autoCalendar.MonthsAgo] = {1}>} [Sales])

But I would still love to understand why the previous formula does not work.

Gabriel
Partner - Specialist III
Partner - Specialist III

@Shoro 

I think the reason why this Sum ({$ <[Order Date.autoCalendar.YearMonth] = $ {"vLastMonth"}>} Sales) didn't work is because you put the double quote and the dollar expansion ($) in the wrong place. See below

 

Sum ({$ <[Order Date.autoCalendar.YearMonth] =  {"$(vLastMonth)"}>} Sales)

Hopefully this helps