Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
RichardLee
Creator
Creator

How can I show the Previous Months Info on KPI

Hi I have the following

 

Sum(if([Invoice Month]=monthname(today()) and [Value Type]='Actual' and [Invoice Date]<=today() and Branch='North', AL_ANALVAL))

 

How can I show the previous months Info in a KPI box?

Labels (1)
  • Chart

1 Solution

Accepted Solutions
stevedark
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi @RichardLee 

Your best bet is to create a field that has month and year in it, which you can do in the load script like this:

LOAD
  [Invoice Date],
  Date(MonthStart([Invoice Date]), 'MMM-YYYY') as [Invoice Month Year],

You can then simplify you statement for this MTD to be:

Sum(if([Value Type]='Actual' and [Invoice Month Year]=monthstart(today()) and Branch='North', AL_ANALVAL))

And the previous month is simply:

Sum(if([Value Type]='Actual' and [Invoice Month Year]=monthstart(addmonths(today(),-1)) and Branch='North', AL_ANALVAL))

You will find your statements are much more efficient if they use set analysis though, so the statements would be:

Sum({<[Value Type]*={'Actual'},[Invoice Month Year]*={'$(=date(monthstart(today()), 'MMM-YYYY'))'},Branch*={'North'}>}AL_ANALVAL)

and

Sum({<[Value Type]*={'Actual'},[Invoice Month Year]*={'$(=date(addmonths(monthstart(today()), -1), 'MMM-YYYY'))'},Branch*={'North'}>}AL_ANALVAL)

The other potential improvement is to change the monthstart(today()) to be max([Invoice Date]), and this will then show you the most recent selected date and the previous month. This way you can time travel and see the difference between other months.

For more ideas on prior period comparison you could take a look at:
https://www.quickintelligence.co.uk/prior-period-comparison/

Hope that helps,
Steve

View solution in original post

3 Replies
stevedark
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi @RichardLee 

Your best bet is to create a field that has month and year in it, which you can do in the load script like this:

LOAD
  [Invoice Date],
  Date(MonthStart([Invoice Date]), 'MMM-YYYY') as [Invoice Month Year],

You can then simplify you statement for this MTD to be:

Sum(if([Value Type]='Actual' and [Invoice Month Year]=monthstart(today()) and Branch='North', AL_ANALVAL))

And the previous month is simply:

Sum(if([Value Type]='Actual' and [Invoice Month Year]=monthstart(addmonths(today(),-1)) and Branch='North', AL_ANALVAL))

You will find your statements are much more efficient if they use set analysis though, so the statements would be:

Sum({<[Value Type]*={'Actual'},[Invoice Month Year]*={'$(=date(monthstart(today()), 'MMM-YYYY'))'},Branch*={'North'}>}AL_ANALVAL)

and

Sum({<[Value Type]*={'Actual'},[Invoice Month Year]*={'$(=date(addmonths(monthstart(today()), -1), 'MMM-YYYY'))'},Branch*={'North'}>}AL_ANALVAL)

The other potential improvement is to change the monthstart(today()) to be max([Invoice Date]), and this will then show you the most recent selected date and the previous month. This way you can time travel and see the difference between other months.

For more ideas on prior period comparison you could take a look at:
https://www.quickintelligence.co.uk/prior-period-comparison/

Hope that helps,
Steve

stevejoyce
Specialist II
Specialist II

Current month should be:

Sum({<[Invoice Month]={"$(=monthname(today()))"}, [Value Type]={'Actual'}, [Invoice Date]<={"<=$(=today())"}, Branch={'North'} >} AL_ANALVAL)

 

previous

Sum({<[Invoice Month]={"$(=monthname(addmonths(today(),-1)))"}, [Value Type]={'Actual'}, Branch={'North'} >} AL_ANALVAL)

RichardLee
Creator
Creator
Author

This also Works perfectly but the Solution I accepted was more elegant.