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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
lucasx15
Contributor III
Contributor III

Previous Month in Set Analys

Hello everybody!

I read some forum posts about "previous month". However, I was not successful in applying.
I have the following situation, I need to lock my Set Analys so that it always takes the previous month. My expression is like this:

COUNT({1<CD_SETOR={22},
		 MESANO_PRIMDIA={"$(=Monthstart(Today())-1)"}>}
		 DISTINCT  NR_NUMERIC))

 

Labels (1)
1 Solution

Accepted Solutions
vchuprina
Specialist
Specialist

In this case you should transform output of MonthStart(Today(),-1) expression to MMM/YYYY format, your expressions are:

COUNT({1<CD_SETOR={22},

MESANO_PRIMDIA={"$(=Date(MonthStart(Today(),-1), 'MMM/YYYY'))"}>}

DISTINCT Value)

Based on today() function, today is 4/28/2022,  Qlik will show the count for the previous month - Mar/2022 even if you select Feb/2022 in MESANO_PRIMDIA 

COUNT({1<CD_SETOR={22},

MESANO_PRIMDIA={"$(=Date(MonthStart(Max(MESANO_PRIMDIA),-1), 'MMM/YYYY'))"}>}

DISTINCT Value)

Based on Max(MESANO_PRIMDIA),  if the latest MESANO_PRIMDIA in your application is Apr/2022 Qlik will show the count for Mar/2022. If you select Mar/2022 Qlik will show data for Feb/2022

Regards,

Vitalii

Press LIKE if the given solution helps to solve the problem.
If it's possible please mark correct answers as "solutions" (you can mark up to 3 "solutions").

View solution in original post

5 Replies
vchuprina
Specialist
Specialist

Hi,

You can add '-1' as a second parameter to monthsstart function

COUNT({1<CD_SETOR={22},
MESANO_PRIMDIA={"$(=Monthstart(Today(),-1))"}>}
DISTINCT NR_NUMERIC))

https://help.qlik.com/en-US/sense/February2022/Subsystems/Hub/Content/Sense_Hub/Scripting/DateAndTim...

Regards,

Vitalii

Press LIKE if the given solution helps to solve the problem.
If it's possible please mark correct answers as "solutions" (you can mark up to 3 "solutions").
lucasx15
Contributor III
Contributor III
Author

Thank you for reply, Vitalii.

 

However, even using the second argument the field still appears null for me in the display. The dimension that I am using MESANO_PRIMDIA. Do I need to put the -1" argument in the dimension as well?

vchuprina
Specialist
Specialist

What do you have in MESANO_PRIMDIA column?

Press LIKE if the given solution helps to solve the problem.
If it's possible please mark correct answers as "solutions" (you can mark up to 3 "solutions").
lucasx15
Contributor III
Contributor III
Author

In column, MESANO_PRIMDIA ,has the date in the format: "MMM/YYYY"

vchuprina
Specialist
Specialist

In this case you should transform output of MonthStart(Today(),-1) expression to MMM/YYYY format, your expressions are:

COUNT({1<CD_SETOR={22},

MESANO_PRIMDIA={"$(=Date(MonthStart(Today(),-1), 'MMM/YYYY'))"}>}

DISTINCT Value)

Based on today() function, today is 4/28/2022,  Qlik will show the count for the previous month - Mar/2022 even if you select Feb/2022 in MESANO_PRIMDIA 

COUNT({1<CD_SETOR={22},

MESANO_PRIMDIA={"$(=Date(MonthStart(Max(MESANO_PRIMDIA),-1), 'MMM/YYYY'))"}>}

DISTINCT Value)

Based on Max(MESANO_PRIMDIA),  if the latest MESANO_PRIMDIA in your application is Apr/2022 Qlik will show the count for Mar/2022. If you select Mar/2022 Qlik will show data for Feb/2022

Regards,

Vitalii

Press LIKE if the given solution helps to solve the problem.
If it's possible please mark correct answers as "solutions" (you can mark up to 3 "solutions").