# Qlik Sense App Development

Announcements
Qlik Analytics Tour 2020 Online. Begins August 10th. Register Today
cancel
Showing results for
Did you mean:
Highlighted
Contributor

## Previous 'N' Month calculation

Hi,

The requirement is, when I select a particular month say 'March' for an year say '2020', All the previous months must also be displayed say 'Jan','Feb' and 'March'. How could i achieve this?   Please help me out.

Labels (1)

11 Replies
Highlighted
Specialist III

## Re: Previous 'N' Month calculation

Where do you want to show? In a Chart?

Highlighted
Contributor

## Re: Previous 'N' Month calculation

In a bar chart as well as in a table view. Once I select the parameter, I need this to reflect in both the analysis.

Highlighted
Partner

## Re: Previous 'N' Month calculation

You can accomplish this by introducing set analysis into your chart and table expression.

The set will differ based on how you want the logict to be, but your header states "Previous 'N' months" so try something like this.

Assuming your original expression is SUM([Amount]) and N=4. I also you have four calendar fields Year, Month, Date and YearMonth that you need to ignore in order to get the expression right. With these assumptions an expression could look like this.

Sum({<Year, Month, YearMonth, Date = {">=\$(=addmonths(max(Date),-4))<=\$(=max(Date))"}>}[Amount])

Plees ekskuse my Swenglish and or Norweglish spelling misstakes
Highlighted
Contributor

## Re: Previous 'N' Month calculation

The expression is not working sir.

My  Requirement is , When i select the  Year is 2020  and Month is May in filter pane, the  line chart should display Jan to May.if I select AUG,the line chart should display 'JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG'.

I want to display like this in table and line chart.

Creator III

Hi,

Try

dimension- Month

Highlighted
Contributor

## Re: Previous 'N' Month calculation

Hi Nitin,

I have tried the expression but its not working .

My Expression is

sum({<MONTH_NAME={"<=\$(=max(MONTH_NAME))"}>}[XXBI_GL_GROUP_BALANCE_V.PTD_VALUE])

Regards,

Dhinesh

Highlighted
Creator III

## Re: Previous 'N' Month calculation

hi,

can you attach you data for this two field, it is easy to find solution

Highlighted
Partner

## Re: Previous 'N' Month calculation

Set modifiers always look for the text of a dual when comparing a value. (Assuming your field is a dual value with month name and month number, probably created by using the Month() function)

Max(MONTH_NAME) will return a numeric value of your dual value and you will have no match. Try replacing max with maxstring() like this.

sum({<MONTH_NAME={"<=\$(= MaxString(MONTH_NAME))"}>}[XXBI_GL_GROUP_BALANCE_V.PTD_VALUE])

Plees ekskuse my Swenglish and or Norweglish spelling misstakes
Highlighted
Contributor

## Re: Previous 'N' Month calculation

Hi,

Apologies, tried something like this but not successful.

sum({<MONTH_NAME={"<=\$(= MaxString(MONTH_NAME))"},[XXBI_GL_GROUP_BALANCE_V.DISPLAY_FLAG]= {"Y"},
[XXBI_GL_GROUP_BALANCE_V.ACCT_GROUP_NAME] = {"Revenue"}>}[XXBI_GL_GROUP_BALANCE_V.PTD_VALUE]).

Regards,

Dhinesh