Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
StefanE
Contributor III
Contributor III

Certain Periods from current year plus all of last 3 years

Hello beautiful people,

I apologize in advance if this has been solved in a previous post. I was not able to find it.

So what I need ist an expression that allows me to mark all periods(YearMonth) of the actual year - with a delay of 1.5  months as well as all periods of past 3 years.

If you it is e.g.  the 15th or > of August the goal is to display all periods up to 202206 of the current year as well as all periods of the last 3 years.

What I've got thus far is a marker for all periods equal with a delay of 1.5 months:

=if(day(today())>15 and month(today())>1,[YEARMONTH] <= (year(addmonths(today(), -1)))*100 + MONTH(addmonths(today(), -1)),

if(day(today())>15 and month(today())=1,

[YEARMONTH] <= (year(addmonths(today(), -1))-1)*100 + MONTH(addmonths(today(), -1)),
[YEARMONTH] <= (year(addmonths(today(), -1)))*100 + MONTH(addmonths(today(), -2))))

and another marker for the last 3 years (including current year) 

=[YEAR]>year(today())-4

 

How to combine the two I haven't figured out yet. 

Since I might need it for NPrinting, so no scripting or set expressions.

If someone could lead me into the right direction, I would be thankful.

Kind regards

Stefan

Labels (3)
1 Solution

Accepted Solutions
StefanE
Contributor III
Contributor III
Author

Hi Edwin,

Thanks for your reply. I want to give the internal customer as much freedom as possible and a marker is what they wanted, so I couldn't use set analysis.

I managed to convert the formula above to do just that: 

Greater than the 15th of the month -> previous period actual year plus going back three full years.

Lower than the 15th of the month -> preprevious period actual year plus going back three full years:  

=if(day(today())>15 and month(today())>1 and [YEAR] >= year(today())-3,
[YEAR.MONTH] <= (year(addmonths(today(), -1)))*100 + MONTH(addmonths(today(), -1)),
if(day(today()) >15 and month(today())=1 and [YEAR] >= year(today())-3,
[YEAR.MONTH] <= (year(addmonths(today(), -1))-1)*100 + MONTH(addmonths(today(), -1)),
if(day(today()) <15 and month(today())>1 and [YEAR] >= year(today())-3,
[YEAR.MONTH] <= (year(addmonths(today(), -1)))*100 + MONTH(addmonths(today(), -2)),
if(day(today()) <15 and month(today())=1 and [YEAR] >= year(today())-3,
[YEAR.MONTH] <= (year(addmonths(today(), -1))-1)*100 + MONTH(addmonths(today(), -2))))))

 

Thanks for the link. I can use variables in other contexts so cheers

Kind regards

Stefan

View solution in original post

2 Replies
edwin
Master II
Master II

this is a common design pattern.  my suggested solution is to compute for the date boundaries dynamically, store them in variables and use the variables in your set analysis, it makes the expression readable.

https://community.qlik.com/t5/New-to-Qlik-Sense/how-to-calculate-previous-year-sales-till-current-ye...

 

StefanE
Contributor III
Contributor III
Author

Hi Edwin,

Thanks for your reply. I want to give the internal customer as much freedom as possible and a marker is what they wanted, so I couldn't use set analysis.

I managed to convert the formula above to do just that: 

Greater than the 15th of the month -> previous period actual year plus going back three full years.

Lower than the 15th of the month -> preprevious period actual year plus going back three full years:  

=if(day(today())>15 and month(today())>1 and [YEAR] >= year(today())-3,
[YEAR.MONTH] <= (year(addmonths(today(), -1)))*100 + MONTH(addmonths(today(), -1)),
if(day(today()) >15 and month(today())=1 and [YEAR] >= year(today())-3,
[YEAR.MONTH] <= (year(addmonths(today(), -1))-1)*100 + MONTH(addmonths(today(), -1)),
if(day(today()) <15 and month(today())>1 and [YEAR] >= year(today())-3,
[YEAR.MONTH] <= (year(addmonths(today(), -1)))*100 + MONTH(addmonths(today(), -2)),
if(day(today()) <15 and month(today())=1 and [YEAR] >= year(today())-3,
[YEAR.MONTH] <= (year(addmonths(today(), -1))-1)*100 + MONTH(addmonths(today(), -2))))))

 

Thanks for the link. I can use variables in other contexts so cheers

Kind regards

Stefan