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

Return only current or latest month results

Hi

I’m new to QlikSense and to code/script writing.

I am trying to return only the latest month values from quite a large dataset.

I have a table with amongst others the following fields

CovPer

PremRec

CovPerDate

202001

50,000

202001

202002

30,000

202002

202003

45,000

202003

202004

60,000

202004

 

CovPerDate is a column I’ve added via script to convert CovPer to dateformats

I am trying to create a pivot table or graph that only shows the latest month.

i.e.

202004

60 000

 

I have created so far:

  • A variable: vLatestMonth as follows:

=maxString(CovPerDate)

  • A measure as follows:

sum({<Date ={'$(=$(vLatestmonth))'}>}PremRec)

 

Using the above I get:

vLatestMonth

Premrec

202004

185,000

 

Where am I going wrong?

All help appreciated

1 Solution

Accepted Solutions
NitinK7
Specialist
Specialist

Hi,

Try like Below

Dimension-  CovPer

Measure-  Sum({<CovPer={"$(=Max(Date(Date#(CovPer,'YYYYMM'),'YYYYMM')))"}>}PremRec)

 

pivot table

NitinK7_0-1615208256660.png

 

View solution in original post

4 Replies
NitinK7
Specialist
Specialist

Hi,

Try like Below

Dimension-  CovPer

Measure-  Sum({<CovPer={"$(=Max(Date(Date#(CovPer,'YYYYMM'),'YYYYMM')))"}>}PremRec)

 

pivot table

NitinK7_0-1615208256660.png

 

JustinM
Contributor III
Contributor III
Author

Works great. Much appreciated

JustinM
Contributor III
Contributor III
Author

How would I change the above expression to add a second expression in order to show the current month as well as the previous month?

NitinK7
Specialist
Specialist

current month-  Sum({<CovPer={"$(=Date(Today(),'YYYYMM'))"}>}PremRec)

previous month - Sum({<CovPer={"$(=Date(AddMonths(Today(), -1),'YYYYMM'))"}>}PremRec)