Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

sum for previous month/(previous YearMonth)

Hello All

I am facing issue with below requirement.

I have a expression as 1)    sum(  {<Type={'123'}>}   sales).

This give me the sum for YearMonth selected.

I need to create one more field which will provide the sum for previous month/(previous YearMonth).

I am getting that using addmonths(YearMonth, -1).  However I am getting error while I integrate this in above expression (1).

I am trying something like   -- >  sum(  {<Type={'123'}, YearMonth= addmonths(YearMonth, -1) >}   sales). 

But it is not working .

Please help me correct above expression. In Expression 1) I need to add logic for previous YearMonth ...

Thanks in advance....

7 Replies
sunny_talwar

Are you using this in a chart where YearMonth is a dimension?

maxgro
MVP
MVP

maybe you need to format the result of addmonths as your YearMonth field, example:

sum({$ <Type={'123'},  YearMonth={'$(=date(addmonths(max(YearMonth),-1),'YYYY MM'))'}>} sales)

pamaxeed
Partner - Creator III
Partner - Creator III

Hi,

i think it is a formatting problem like maxgro stated.

Try to give a look to the sample attached, I am using a variable to hold the previous month in the following format:

YYYY-MM.

Cheers,

Patric

simenkg
Specialist
Specialist

I usually do this by creating a MonthCounter-field in my master calendar.

Calendar:

load %Datekey,

%Datekey as Date,

Year(%DateKey)&'-'&Month(%Datekey) as YearMonth,

Autonumber(Year(%DateKey)&'-'&Month(%Datekey),'MonthCounter') as MonthCounter

resident tempDates order by %DateKey asc;

Then you can use the expression

sum({$ <Type={'123'},  YearMonth=, MonthCounter={$(=Max(MonthCounter)-1)}>} sales)


Regards

SKG

Anonymous
Not applicable
Author

Yes. I am using in chart as a Set analysis expression.

Anonymous
Not applicable
Author

Thanks a lot Maxgro.. It worked for me with slight change. 

Can you please explain me how/where  to use the $ and '=' which u used before date.  I do not understand how to write these set analysis explression. 

maxgro
MVP
MVP

dollar sign expansion

I can't explain better than Henric

The Magic of Dollar Expansions