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: 
Navars
Creator
Creator

how to create a flag in script for PYTD for completed month

Hell Peeps,

while creating calendar itself i am loading the max date should be completed month( ex. today is 8/5/2022 its not a monthend date so i am taking previous monthend as maxdate in my calendar)

Load

min(Date) as minDate,
if(Today()=MonthEnd(Today()), Today(), MonthEnd(AddMonths(Today(),-1))) as maxDate

Resident [Data Analysis];

I have created a flag for YTD like below

YeartoDate(TempDate)*-1 as CurYTDFlag   

expected result: 1/1/2022 to 7/31/2022   and its coming fine

coming to PYYTD its not working as expected

YeartoDate(TempDate,-1)*-1 as LastYTDFlag

if i use above im getting  1/1/2021 to 8/04/2021 that is not correct

as per my requirement i need to get the LYTD is : 1/1/2021 to 7/31/2021

Thanks in Advance !!

 

Regards,

Sra1..

  

Labels (4)
1 Solution

Accepted Solutions
Navars
Creator
Creator
Author

i tried with below one, i am getting the expected result. like if current date is not equal to monthend data the it will provide the previous monthend date.

YearToDate((TempDate), -1,1,if(Today()=MonthEnd(Today()), Today(), MonthEnd(AddMonths(Today(),-1))))*-1 as LastYTDFlag

View solution in original post

6 Replies
G3S
Creator III
Creator III

try 

YearToDate(TempDate), -1, Month(Today())-1)*-1 as LastYTDFlag

Navars
Creator
Creator
Author

Thanks for your response.

its not giving the expected output, it giving 7/1/2021 to 8/8/2021 only.

expected result is 1/1/2021 to 7/31/2021.

G3S
Creator III
Creator III

please try:
YeartoDate((TempDate,-1),MonthEnd(Month(Today())-1))*-1 as LastYTDFlag

orlandpol
Contributor
Contributor

thank you for the useful information

Navars
Creator
Creator
Author

this expression is also not giving the expected result.

 

Navars
Creator
Creator
Author

i tried with below one, i am getting the expected result. like if current date is not equal to monthend data the it will provide the previous monthend date.

YearToDate((TempDate), -1,1,if(Today()=MonthEnd(Today()), Today(), MonthEnd(AddMonths(Today(),-1))))*-1 as LastYTDFlag