Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
JishnuGS
Partner - Contributor III
Partner - Contributor III

How to calculate previous months data when selecting current month ?

Hi Team,

I want to populate the pervious 3 months data when I'm selecting a month name.

JishnuGS_0-1606476231749.png

Paid Month Long Name is my filter. For example if I select April 2020, I need to get the Sum(POCA) of March 2020, February 2020 and January 2020.

Could you please help me with the query?

Thanks,
Jishnu 

2 Solutions

Accepted Solutions
Taoufiq_Zarra

@JishnuGS  Maye be like this ?

=Sum({1<[Paid Month Long Name] ={">$(=addmonths(max([Paid Month Long Name]),-3))<$(=max([Paid Month Long Name])) "}>} POCA)

Make sure that

SET LongMonthNames='January;February;March;April;May;June;July;August;September;October;November;December';

for example :

Sample:
LOAD [Paid Month ID],Date#([Paid Month Long Name],'MMMM YYYY') as [Paid Month Long Name],Date(Date#([Paid Month Long Name],'MMMM YYYY')) as [Paid Month Date], POCA INLINE [
    Paid Month ID,Paid Month Long Name, POCA
    1, April 2020,1
    2, March 2020,2
     3, March 2019,3
    
];

 

output:

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") 😉

View solution in original post

JishnuGS
Partner - Contributor III
Partner - Contributor III
Author

Hi @Taoufiq_Zarra ,

To get only the single value in the column  

Pervious 1st month
Sum({1<[Paid Month Long Name] ={">$(=addmonths(max([Paid Month Long Name]),-2))<$(=max([Paid Month Long Name])) "}>} POCA)

Pervious 2nd month
Sum({1<[Paid Month Long Name] ={">$(=addmonths(max([Paid Month Long Name]),-3))<$(=max([Paid Month Long Name])-32) "}>} POCA)

Pervious 3rd month
Sum({1<[Paid Month Long Name] ={">$(=addmonths(max([Paid Month Long Name]),-4))<$(=max([Paid Month Long Name])-63) "}>} POCA)

Thank you !!!!!

 

View solution in original post

5 Replies
Taoufiq_Zarra

@JishnuGS  Maye be like this ?

=Sum({1<[Paid Month Long Name] ={">$(=addmonths(max([Paid Month Long Name]),-3))<$(=max([Paid Month Long Name])) "}>} POCA)

Make sure that

SET LongMonthNames='January;February;March;April;May;June;July;August;September;October;November;December';

for example :

Sample:
LOAD [Paid Month ID],Date#([Paid Month Long Name],'MMMM YYYY') as [Paid Month Long Name],Date(Date#([Paid Month Long Name],'MMMM YYYY')) as [Paid Month Date], POCA INLINE [
    Paid Month ID,Paid Month Long Name, POCA
    1, April 2020,1
    2, March 2020,2
     3, March 2019,3
    
];

 

output:

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") 😉
JishnuGS
Partner - Contributor III
Partner - Contributor III
Author

Hi @Taoufiq_Zarra ,

Thank you!

I'm getting the values now. 
But how can we eliminate the below highlighted values. I want pervious 3 month data, previous 1 is working fine but in previous 2 adding the previous 1 value also. so on

JishnuGS_0-1606486062295.png

 

Taoufiq_Zarra

@JishnuGS  I think its correct

between date not equal

Regards,
Taoufiq ZARRA

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

(you can mark up to 3 "solutions") 😉
JishnuGS
Partner - Contributor III
Partner - Contributor III
Author

@Taoufiq_Zarra not equal  is not working 

JishnuGS
Partner - Contributor III
Partner - Contributor III
Author

Hi @Taoufiq_Zarra ,

To get only the single value in the column  

Pervious 1st month
Sum({1<[Paid Month Long Name] ={">$(=addmonths(max([Paid Month Long Name]),-2))<$(=max([Paid Month Long Name])) "}>} POCA)

Pervious 2nd month
Sum({1<[Paid Month Long Name] ={">$(=addmonths(max([Paid Month Long Name]),-3))<$(=max([Paid Month Long Name])-32) "}>} POCA)

Pervious 3rd month
Sum({1<[Paid Month Long Name] ={">$(=addmonths(max([Paid Month Long Name]),-4))<$(=max([Paid Month Long Name])-63) "}>} POCA)

Thank you !!!!!