Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
TheresaB_4
Contributor III
Contributor III

Expression set to display current month, previous month and next month

Good morning everyone,

 

I have an if statement in the expression editor that will display the current month, previos month,next month, when you look at the report. Based on the [MeteringEndDate]
it is a pivot report.

This use to work but not anymore, now I am not sure why? Would love some advice. Maybe even an easier solution.

Expression:

if(
num(Month(Date(MeteringEndDate))) = num(Month(Date(Today()))) and Year(MeteringEndDate)=Year(Today()),monthname(MeteringEndDate),
if(num(Month(Date(Today())))-num(Month(Date(MeteringEndDate)))=1 and Year(MeteringEndDate)=Year(Today()),monthname(MeteringEndDate),
      if(num(Month(Date(MeteringEndDate)))-num(Month(Date(Today())))=1 and Year(MeteringEndDate)=Year(Today()),monthname(MeteringEndDate),
 
      if(num(Month(Date(Today())))-num(Month(Date(MeteringEndDate)))=11 and Year(MeteringEndDate)>Year(Today()),monthname(MeteringEndDate),//check in december2023
          if(num(Month(Date(MeteringEndDate)))-num(Month(Date(Today())))=11 and Year(Today())-Year(MeteringEndDate)=1,monthname(MeteringEndDate),'')
            )
        )
 
      )
   )


What it should look like

TheresaB_4_0-1707818132581.png

 



Thanks so much

 

Kind regards

Theresa

Labels (1)
1 Solution

Accepted Solutions
LRuCelver
Partner - Creator III
Partner - Creator III

In the script:

Data:
NoConcatenate Load
    MonthName(MeteringEndDate) as MeteringEndMonth,
    Year(MeteringEndDate) as MeteringEndYear,
    MeteringEndDate;
Load
    AddMonths(AddYears(YearStart(Today()), -1), RecNo()-1) as MeteringEndDate
AutoGenerate 24;

 In the expression:

={<MeteringEndDate={">=$(=AddMonths(MonthStart(Today()), -1)) <=$(=AddMonths(MonthStart(Today()), 1))"}>} Aggr(Only(MeteringEndMonth), MeteringEndMonth)

View solution in original post

4 Replies
LRuCelver
Partner - Creator III
Partner - Creator III

Here is my data:

Data:
NoConcatenate Load
    MonthName(Date) as Month,
    Year(Date) as Year,
    Date;
Load
    AddMonths(AddYears(YearStart(Today()), -1), RecNo()-1) as Date
AutoGenerate 24;

And here the expression and the result:

={<Date={">=$(=AddMonths(MonthStart(Today()), -1)) <=$(=AddMonths(MonthStart(Today()), 1))"}>} Aggr(Only(Month), Month)

LRuCelver_0-1707829204976.png

 

Make sure to disable "Include null values".

TheresaB_4
Contributor III
Contributor III
Author

Hi,

 

Maybe this is a stupid question but do I now replace my date field "MeteringEndDate" with your "Date" field?

 

Thanks

Theresa

LRuCelver
Partner - Creator III
Partner - Creator III

In the script:

Data:
NoConcatenate Load
    MonthName(MeteringEndDate) as MeteringEndMonth,
    Year(MeteringEndDate) as MeteringEndYear,
    MeteringEndDate;
Load
    AddMonths(AddYears(YearStart(Today()), -1), RecNo()-1) as MeteringEndDate
AutoGenerate 24;

 In the expression:

={<MeteringEndDate={">=$(=AddMonths(MonthStart(Today()), -1)) <=$(=AddMonths(MonthStart(Today()), 1))"}>} Aggr(Only(MeteringEndMonth), MeteringEndMonth)
TheresaB_4
Contributor III
Contributor III
Author

Thank you so much.
This is great.