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

date over year on same chart

Hi,

I would like to plot ACT and LY ACT over date on the same chart.

Output chart should be something like:

  

DateACTLY
26-7-2015150170
27-7-2015164213
28-7-2015272277
29-7-2015308380
30-7-2015382418
31-7-2015487437
1-8-2015515513
2-8-2015613649
3-8-2015735784
4-8-2015833929
5-8-2015838936
6-8-20159601069

To achieve that end, I've created periods table

   

periodIdperiodNmLY_periodId
1026-7-2014null
1127-7-2014null
1228-7-2014null
1329-7-2014null
1430-7-2014null
1531-7-2014null
161-8-2014null
172-8-2014null
183-8-2014null
194-8-2014null
205-8-2014null
216-8-2014null
2226-7-201510
2327-7-201511
2428-7-201512
2529-7-201513
2630-7-201514
2731-7-201515
281-8-201516
292-8-201517
303-8-201518
314-8-201519
325-8-201520
326-8-201521

(NOTE: period can also be a month, or quarter)

...and source table

 

PeriodIdmargin
10170
11213
12277
13380
14418
15437
16513
17649
18784
19929
20936
211069
22150
23164
24272
25308
26382
27487
28515
29613
30735
31833
32838
33960

Business requirements:

reference period = selected period

chart scope:

min_periodId = [reference period] - $(periodsBack)

max_periodId  = [reference period] + $(periodsForward)

Dimension: periodNm

Expressions:

  • margin CY
  • margin LY

Question: how can I plot two parallel periods with 2 different periodId?

1 Solution

Accepted Solutions
swuehl
MVP
MVP

Maybe like attached?

View solution in original post

8 Replies
swuehl
MVP
MVP

Maybe like attached?

sunny_talwar

If you want the front end solution, you can try this. Right now it isn't going to work when you make a selection, but when you have continuous dates, the solution should work flawlessly. PFA

Expression 1: Sum({<periodNm = {"$(='>=' & Date(Max(periodNm)-12) & '<=' & Date(Max(periodNm)))"}>}margin)

Expression 2: Above(Sum({<periodNm = {"$(='>=' & Date(AddYears(Max(periodNm)-12, -1)) & '<=' & Date(AddYears(Max(periodNm), -1)))"}>} margin),12)

You should be able to use a variable to determine how many days you want to go back based on user input in a input box and use the variable to replace 12 (highlighted in red)

Best,

Sunny

swuehl
MVP
MVP

Sunny,

isn't that also a script based solution, just a different one (using the OPs script based solution)

My intention was to show that if we change the script a little, it makes the front end much easier.

sunny_talwar

Hahahaha sure Stefan, Its a front end script based solution

I, by no means, wanted to suggest that my solution is better than yours. In fact, I would love if you or somebody else can point out which one is better solution (always trying to learn a more efficient way of doing stuff), which in this case would definitely be yours because you simplify everything in the script. But I think listing out all possibilities is also a good idea, giving the Questioner/Poster a chance to decide which options suits him the best for his situation. I am sure you will agree.

Best,

Sunny

Not applicable
Author

swuehl,

I like this approach. It seems to be clean and elegant. Can I also split it into two expressions?

  • CY - Sum({<Type = {'CY'}>}Value)
  • LY - Sum({<Type = {'LY'}>}Value)

The solutions only works if 'AsOfDate' is used as dimension in the chart. In my model its important to use date as dimension. Is it possible to revert the AsOf table?

sunny_talwar

Correct me if I am wrong Stefan, but I think this model can only work if you create a new field name, you can call it whatever you want, but this is the field you will need to use to make the chart to work.

HTH

Best,

Sunny

swuehl
MVP
MVP

Dror,

1) Sure, you can exactely use these two expressions instead of the dimension Type in the chart

2) Not sure what you mean with reverting the AsOfTable.

As Sunny, said, you can rename fields, but there will be essentially one field that shows the book-keeping date (where the value was booked) and another field that acts as a translation / link to another date (same date as bookkeeping for CY, one year ahead for LY).

If you make selections only on the book keeping date, you can use some set analysis to apply these selections to the chart.

If it's just the wording AsOfDate, you can rename the field or label in the chart.

Anyway it will be hard to fulfill every possible requirement, for example, in Sunny's solution, you will see some issues if you select a PeriodNm.

Not applicable
Author

swuehl and Sunny,

sorry for my late reaction. I've implemented the AsOf approach and it works like  a charm

THANKS ALOT

Dror