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: 
mario-sarkis
Creator II
Creator II

Calculation Of current and Previous Month

Please find attachement my sample data :

i need to calculate the sum of amount of max periodDate (of current Date)

and compare it with the Previous month

ID                SumAmountMaxPeriodDate                      SumAmountPerviousMonth

this will b clear when the sample data that i have

sum({<[PeriodDate]={$(=max([PeriodDate]))}>}[Amount] it give me a Sum of CurrentMonth (as max periodDate) and

for the Previous Month i tried this expression

sum({<[PeriodDate]={$(=num(monthend(AddMonths(max([PeriodDate]),-1))))}>}[Amount])   it give me zero

8 Replies
Gysbert_Wassenaar

MonthEnd will return the last second of a month: i.e. something like 01-01-2015 23:59:59. Your PeriodDate values won't have that time fraction. If you want the last day of the previous month try $(=num(MonthStart(max([PeriodDate]))-1) )


talk is cheap, supply exceeds demand
sunilkumarqv
Specialist II
Specialist II

Try like this

sum({<[PeriodDate]={">=$(=max([PeriodDate])-1)"}>}[Amount]

mario-sarkis
Creator II
Creator II
Author


hi Gysbert should i add AdMonths() before the periodeDate?

ramoncova06
Partner - Specialist III
Partner - Specialist III

you can use floor to get rid of the fractions from the month end function, and when using monthend you can define the offset


sum({<[PeriodDate]={$(=num(floor(monthend((max([PeriodDate]),-1))))}>}[Amount])

mario-sarkis
Creator II
Creator II
Author

Hi Ramon i tried this Expression and it give me Zero anything wrong in the syntax ?

sum({<[PeriodDate]={$(=num(floor(monthend(max([PeriodDate]))-1)))}>}[Amount])

mario-sarkis
Creator II
Creator II
Author

Hi Sunil Kumar this is giving me the Sum of Amount of the Current month not the Previous one

Can you help to find the sum of Amount of the Previous Month ?

mario-sarkis
Creator II
Creator II
Author

this expression is givin me Zero

ramoncova06
Partner - Specialist III
Partner - Specialist III

you are missing the coma for the monthend function

sum({<[PeriodDate]={$(=num(floor(monthend(max([PeriodDate]),-1))))}>}[Amount])