New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

New Contributor II

Current and Previous Year/Month Calculation in Set Analysis

I have posting dates from 2015, 2016, 2017, and 2018 and I have created a master calendar for the posting dates. I have to calculate the charge amount for the current year/month in the selection and for the prevoius year/month. Also, if I select 2016 then for previous year it should show zero as 2016 is my first year.

I am using the following set analysis syntax but I am getting 0 as my value for every selection

sum(

{<
Year = {"=\$Year - 1"}
, Corrected = {'N'}
>} [Amount])
-
sum(
{<
Year = {"=\$Year - 1"}
, Corrected = {'Y'}
>} [Amount])

1 Solution

Accepted Solutions
MVP

Re: Current and Previous Year/Month Calculation in Set Analysis

May be try this

```Sum({<Year = {"\$(=Max(Year) - 1)"}, Corrected = {'N'}>} [Amount])
-
Sum({<Year = {"\$(=Max(Year) - 1)"}, Corrected = {'Y'}>} [Amount])```
7 Replies
MVP

Re: Current and Previous Year/Month Calculation in Set Analysis

May be try this

```Sum({<Year = {"\$(=Max(Year) - 1)"}, Corrected = {'N'}>} [Amount])
-
Sum({<Year = {"\$(=Max(Year) - 1)"}, Corrected = {'Y'}>} [Amount])```
New Contributor II

Re: Current and Previous Year/Month Calculation in Set Analysis

Thank You. It worked.

New Contributor II

Re: Current and Previous Year/Month Calculation in Set Analysis

Hi Sunny,

The code you provided is working fine when I select a Year, Quarters, or Months but it gives me zero for the previous year when I pick a custom date range.

MVP

Re: Current and Previous Year/Month Calculation in Set Analysis

May be ignore selection in the date range?

Highlighted
New Contributor II

Re: Current and Previous Year/Month Calculation in Set Analysis

Is there any way to include the custom date range? I mean using a variable and then create a toggle button to switch between a custom date range and direct selection.

MVP

Re: Current and Previous Year/Month Calculation in Set Analysis

I might be able to help better if you are able to provide a sample to check this out

New Contributor II

Re: Current and Previous Year/Month Calculation in Set Analysis

Sure, I will share by the EOD.