Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
andrea90casa
Creator
Creator

Current vs Previous

Hi at all,

I have a data set like this one

Month_IDDateMonthAmount

1

01/01/2017

Gen

20
201/02/2017Feb37
301/03/2017

Mar

17
401/04/2017

Apr

50
501/05/2017May14
601/06/2017Jun22
701/07/2017Jul18
801/08/2017Ago10
901/09/2017Sep25
1001/10/2017Oct24
1101/11/2017Nov13
1201/12/2017Dec19

I create a simple table with months on rows and sum(amount) on first column. Than i created a calculated field like second column:

sum( {$<Month_ID = {$(=Max(Month_ID)-1)>}Amount)

But the resul is that it shows only amount for November and all the other are zero, instead i would like to obtain a table with for example on April i can see 17 for second column because the amount of the previous month are amount of march, and this for all the other rows

How can I get it?

Andrea

1 Solution

Accepted Solutions
antoniotiman
Master III
Master III

Hi Andrea,

it would be better to use As-OfTable technique

https://community.qlik.com/blogs/qlikviewdesignblog/2015/11/02/the-as-of-table#comment-49905

see exemple

Table:
Load Date,Amount Inline [
Month_ID,Date,Month,Amount
12,1/12/2016,Dec,30
1,1/1/2017,Gen,20
2,1/2/2017,Feb,37
3,1/3/2017,Mar,17
4,1/4/2017,Apr,50
5,1/5/2017,May,14
6,1/6/2017,Jun,22
7,1/7/2017,Jul,18
8,1/8/2017,Ago,10
9,1/9/2017,Sep,25
10,1/10/2017,Oct,24
11,1/11/2017,Nov,13
12,1/12/2017,Dec,19]
;

Calendar:
Load Date,MonthName(Date) as MonthName,
Month(Date) as Month_ID,Year(Date) as Year
Resident Table;

TmpAsOfMonth:
LOAD DISTINCT MonthName Resident Calendar;
Join (TmpAsOfMonth) Load
MonthName as AsOfMonth
Resident TmpAsOfMonth;

AsOfCalendar:
Load MonthName,
AsOfMonth,
Round((AsOfMonth-MonthName)*12/365.2425) as MonthDiff,
Year(AsOfMonth)-Year(MonthName) as YearDiff
Resident TmpAsOfMonth
Where AsOfMonth >= MonthName;

Drop Table
TmpAsOfMonth;

In Front End

Dimension AsOfMonth

Expression

Sum({<MonthDiff={0}>} Amount)

Sum({<MonthDiff={1}>} Amount)

Regards,

Antonio

View solution in original post

11 Replies
sergio0592
Specialist III
Specialist III

Use :

above(sum(Amount))

or create a variable v_previous=Month_ID-1 and use in your set analysis as

sum({<Month_ID={$(v_previous)}>} Amount)

andrea90casa
Creator
Creator
Author

Hi Jean-Baptiste

Thanks for your answer.

The first solution is ok but give to me problem when i want at example compare amount of Jan 2017 with amount of Dec 2016.

The second one don't give to me any result

I share a picture of the output

sasiparupudi1
Master III
Master III

May be like this?

andrea90casa
Creator
Creator
Author

Hi Sasidhar

Could you share me the formula you have used? because with PE i can't open your file.

Andrea

sasiparupudi1
Master III
Master III

May be try the following script

x:
Load Month_ID,Date,Month,Amount,
Year(Date) as Year;
Load * Inline
[
Month_ID,Date,Month,Amount
12,1/12/2016,Dec,30
1,1/1/2017,Gen,20
2,1/2/2017,Feb,37
3,1/3/2017,Mar,17
4,1/4/2017,Apr,50
5,1/5/2017,May,14
6,1/6/2017,Jun,22
7,1/7/2017,Jul,18
8,1/8/2017,Ago,10
9,1/9/2017,Sep,25
10,1/10/2017,Oct,24
11,1/11/2017,Nov,13
12,1/12/2017,Dec,19



];
Final:
NoConcatenate Load Month_ID,Date,Year,Month,Amount,
Previous(Amount) as PreviousAmount
Resident x
Order by Year,Date Desc;

Drop Table x;

effinty2112
Master
Master

Hi Andrea,

Add the expression shown here to a straight table:

Month_ID Date Month Sum(Amount) Above(TOTAL Sum(Amount))
101/01/2017Gen20 
201/02/2017Feb3720
301/03/2017Mar1737
401/04/2017Apr5017
501/05/2017May1450
601/06/2017Jun2214
701/07/2017Jul1822
801/08/2017Ago1018
901/09/2017Sep2510
1001/10/2017Oct2425
1101/11/2017Nov1324
1201/12/2017Dec1913

Cheers

Andrew

andrea90casa
Creator
Creator
Author

Hi Andrew,

But this is works even if i have data for two years and i want to select only one (ex° 2017)? Because I would like to compare even Jan 2017 with Dec 2016 for example.

I tried to create Month_ID Because, for example, Dec 2017 has 12 as Month_ID and Jan 2018 has 13.

But I can't create a Set Analysis that works in this situation and i don't know where is the problem

Andrea

andrea90casa
Creator
Creator
Author

I founda sort of solution using set analysis but the problem is that when i create a bar chart i can see only one month (which i select with Month Field), instead i would like to see all the twelve month at the same time with value of the previous month on each bar.

effinty2112
Master
Master

Hi Andrea,

The straight table I showed had two expressions modify them to

Sum({$<Year, Month>}Amount)

and

Above(TOTAL Sum({$<Year,Month>}Amount))

and the expressions will disregard selections made on the fields year and month, so if you select on these fields you should see the rows you need.

Cheers

Andrew