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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
satya_s
Partner - Contributor III
Partner - Contributor III

Calculate Previous Month Cost based on filter selection

Hi,

I am trying to show the month (selected) and previous month cost in a report but for some reason the previous month cost is showing the same value as current month. I need some help identify the issue.

 

Step 1: Loading the data 

[DealsData]:
LOAD
Date(Floor(TRAFFIC_DATE),'YYYY-MM-DD') AS TRAFFIC_DATE,
"YEAR",
"MONTH",
CARRIER_SHORT_NAME,
SUM(COST) AS COST
FROM [lib://Du_QS_QVD_Folder_Conn/DealsData.qvd] (qvd)
GROUP BY Date(Floor(TRAFFIC_DATE),'YYYY-MM-DD'),
"YEAR",
"MONTH",
CARRIER_SHORT_NAME;

Step 2:

Created a calculated column in the sheet i.e.

PREVIOUS_MONTH_COST = Sum({$<YEAR,MONTH, TRAFFIC_DATE={"=$(=Date(addmonths(Max(TRAFFIC_DATE),-1),'YYYY-MM'))"}>}COST)

 

Step 3: On selecting the Month and Year, the Previous Month Cost shows the same value as Current Month Cost

satya_s_2-1704814835039.png

 

 

I tried the following formula too but that didn't work either

Sum({<TRAFFIC_DATE={">=$(=Date(MonthStart(addmonths(Max(TRAFFIC_DATE),-1)),'YYYY-MM-DD')) <=$(=Date(addmonths(Max(TRAFFIC_DATE),-1),'YYYY-MM-DD'))"},YEAR,MONTH>}COST)

satya_s_1-1704814789831.png

 

Can you please help rectify the expression above?

Labels (1)
2 Solutions

Accepted Solutions
MatheusC
Specialist II
Specialist II

@satya_s 

see with the formula below and ignoring month= filter

sum({<TRAFFIC_DATE={">=$(=Date(MonthStart(Date(Max(TRAFFIC_DATE)),-1),'YYYY-MM-DD')) <=$(=Date(MonthEnd(Date(Max (TRAFFIC_DATE)),-1),'YYYY-MM-DD'))"},MONTH=>}COST)

Att, Matheus

Did you find a solution to your question? Mark the solution as accepted and if you found it useful, press the like button!

View solution in original post

satya_s
Partner - Contributor III
Partner - Contributor III
Author

Thank you @MatheusC  !! The solution worked and the key to this is to ignore the month filter in the dashboard report which you mentioned. That really helped otherwise it was showing 2 entries (one for current month and another for the previous month). 

View solution in original post

2 Replies
MatheusC
Specialist II
Specialist II

@satya_s 

see with the formula below and ignoring month= filter

sum({<TRAFFIC_DATE={">=$(=Date(MonthStart(Date(Max(TRAFFIC_DATE)),-1),'YYYY-MM-DD')) <=$(=Date(MonthEnd(Date(Max (TRAFFIC_DATE)),-1),'YYYY-MM-DD'))"},MONTH=>}COST)

Att, Matheus

Did you find a solution to your question? Mark the solution as accepted and if you found it useful, press the like button!
satya_s
Partner - Contributor III
Partner - Contributor III
Author

Thank you @MatheusC  !! The solution worked and the key to this is to ignore the month filter in the dashboard report which you mentioned. That really helped otherwise it was showing 2 entries (one for current month and another for the previous month).