Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
sergeyko
Partner - Contributor III
Partner - Contributor III

Trying to calc month-over-month ratio of current vs past with a twist

Hi there,

I'm trying hard to build a chart that would show a monthly trend for the following ratio:

(sum of prices of items from previous month - sum of prices of items from current month * ) / sum of prices of items from previous month

Task A is to build a chart that will show this ratio for each month left in the list after a user selects Year(s) and Month(s) in filters. I'm struggling to define a "previous month" selection that would work for all available months. Tried the Above() function and it worked fine, with an exception of the first month, which I also want to cover if I have the data for the preceding month in my entire data set (regardless of applied filters).

Task B ( * ) is to limit the second component in the original ratio so that it only sums prices of items that existed in the previous month and caps the prices so that these do not exceed the prices of the same items from the previos month.

I'd appreciate any sugestions on both set expressions and data transforamtion approaches that would help me solve both assignments.

My data looks like as follows. Things to notice are: a) items vary between months, b) prices of same items vary between months.

Task A output for Jan 2017 will be (150+250+350 - 160+200+240) / 150+250+350

Task B turns out a bit different as (150+250+350 - 150[capped price of item 123]+0[item 124 was absent]+240[new price of item 125]) / 150+250+350

YearMonthItem #Price
2016Dec123150
2016Dec125250
2016Dec135350
............
2017Jan123160
2017Jan124200
2017Jan125240
2017Feb123150
2017Feb124220
2017Feb126300
Labels (3)
2 Replies
sunny_talwar

What are you chart dimensions? The best way to handle this is to use The As Of Table

sergeyko
Partner - Contributor III
Partner - Contributor III
Author

Hi Sunny,

Thank you for the directions. My chart should show the calculated ratio through available months - nothing fancy there.

I'm already looking into how to adapt the powerful concept of AsOf table to my scenario.