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: 
Not applicable

What's wrong with this Set analysis with Date and Date#

Hello everyone,

Here's the expression I try to use to calculate sales of last month>

=sum({<Date={"$(=date(addmonths(date#(Month&'/'&Year ,'MMM/YYYY'),-1),'MM/YYYY'))"}>}[sales])

The expression: date(addmonths(date#(Month&'/'&Year ,'MMM/YYYY'),-1),'MM/YYYY') gives the right result '01/2015'

and: sum({<Date={"01/2015"}>}[sales]) also gives the right result.

however it doesn't work if I combine them. 

Can you advise please? THanks a lot!

1 Solution

Accepted Solutions
MK_QSL
MVP
MVP

=SUM({<Date = {'>=$(=Date(MonthStart(AddMonths(Today(),-1)),'DD/MM/YYYY'))<=$(=Date(MonthEnd(AddMonths(Today(),-1)),'DD/MM/YYYY'))'}>}sales)


or

=SUM({<Date = {'>=$(=Date(MonthStart(AddMonths(Max(Date),-1)),'DD/MM/YYYY'))<=$(=Date(MonthEnd(AddMonths(Max(Date),-1)),'DD/MM/YYYY'))'}>}sales)

View solution in original post

5 Replies
MK_QSL
MVP
MVP

What is the format of your Date field?

Not applicable
Author

the format of Date field is "DD/MM/YYYY"

Month format= 'Jan','Feb' etc

MK_QSL
MVP
MVP

Then how can you compare

DD/MM/YYYY with MM/YYYY ?

Below is wrong...

sum({<DD/MM/YYYY={"MM/YYYY"}>}[sales])

Not applicable
Author

Both of them are Date, no? Could you please explain? THanks

How should I modify the set analysis so I get the sales of January?

Do i have to write sum({<Year={$(=Year(addmonths(Date#(Month&'/'&Year ,'MMM/YYYY'),-1)))},Month={$(=Month(addmonths(Date#(Month&'/'&Year ,'MMM/YYYY'),-1)))}>}sales)?

Thank!

MK_QSL
MVP
MVP

=SUM({<Date = {'>=$(=Date(MonthStart(AddMonths(Today(),-1)),'DD/MM/YYYY'))<=$(=Date(MonthEnd(AddMonths(Today(),-1)),'DD/MM/YYYY'))'}>}sales)


or

=SUM({<Date = {'>=$(=Date(MonthStart(AddMonths(Max(Date),-1)),'DD/MM/YYYY'))<=$(=Date(MonthEnd(AddMonths(Max(Date),-1)),'DD/MM/YYYY'))'}>}sales)