Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
chrequena_88
Contributor II
Contributor II

Line Chart showing percent variance relative to the minimum date in the current user selection

Hi everyone, 
I need to create a line chart that shows the percent variance of a multiple products' price over time. As the price of the products might differ from each other quite a lot, the comparison must be done in respect to the its own price at the minimum date possible according the user selection.

 A sample data look like:

PRODUCT_IDDATEPRICE
11.1.202010
21.1.2020150
31.1.2020300
12.1.202012
22.1.2020120
32.1.2020320
13.1.202015
23.1.2020110
33.1.2020330
14.1.202019
24.1.2020100
34.1.2020350
15.1.202025
25.1.202095
35.1.2020400

 

The percent variance would look like this in a straight table:

PRODUCT_IDDATEPRICEPercent Variance
11.1.202010100 %
12.1.202012120 %
13.1.202015150 %
14.1.202019190 %
15.1.202025250 %
21.1.2020150100 %
22.1.202012080 %
23.1.202011073 %
24.1.202010067 %
25.1.20209563 %
31.1.2020300100 %
32.1.2020320107 %
33.1.2020330110 %
34.1.2020350117 %
35.1.2020400133 %


I am having issues when creating the right expression in the line chart measure. The current (AND NOT WORKING) expression in my line chart is the following one:
 - PRICE / Only({$<DATE={'$(=Min(DATE))'}>} PRICE)

The line chart dimensions are currently configure as following:
 - Group: date
 - Line: product_id 


The expected output would be:

Price Evolution Over time respect to initial pricePrice Evolution Over time respect to initial price

 

 

 

 

 

 

 

Thank you in advance.

Qlik Sense 

Labels (2)
1 Solution

Accepted Solutions
chrequena_88
Contributor II
Contributor II
Author

Hi Gary,
Thank you for your response. Honestly, your last suggestion didn't work for my real dataset. I believe that the reason for this is that I have simplified the real case incorrectly, and therefore your code works for the simplified case but not for the real one. 

In any case, your explanation about the use of "Total <PRODUCTI_ID>" did help me. Hence, I have modified my initial code as follows: 

 - PRICE / Only({$<DATE={'$(=Min(DATE))'}>}  Total <PRODUCTI_ID> PRICE)

And the above code works exactly as expected. 

Once again, thank you for your help!

View solution in original post

5 Replies
GaryGiles
Specialist
Specialist

Try this:

=Only(PRICE)/only({$<DATE={'$(=MIN(Total <PRODUCT_ID> DATE))'}>} Total <PRODUCT_ID> PRICE)

chrequena_88
Contributor II
Contributor II
Author

Hi Gary, 
Thanks for your piece of advice. But unfortunately, that didn't work.

Might I ask you what was your idea of including the keyword "TOTAL" and the modifier <PRODUCT_ID>?I think that I don't need to include a modifier for product (<PRODUCT_ID>)as I need that the products showed in the chart change dynamically according user selections. 

chrequena_88
Contributor II
Contributor II
Author

Now the following expression:

Only(PRICE)/only({$<DATE={'$(=MIN( DATE))'}>} Total  PRICE)

works as intended partially. The line chart shows the product' price in percentage relative to its initial price, but some reason the line chart only works when only one fund is selected. That is, when more than one product is selected, the line chart doesn't show any values.

GaryGiles
Specialist
Specialist

The "Total <PRODUCTI_ID>" ensures that min date is specific for each product.  Give this expression a try.  It work for me with your limited data set.

Only(PRICE)/SUM(Total <PRODUCT_ID> IF(DATE=AGGR(MIN(DATE),PRODUCT_ID),PRICE))

chrequena_88
Contributor II
Contributor II
Author

Hi Gary,
Thank you for your response. Honestly, your last suggestion didn't work for my real dataset. I believe that the reason for this is that I have simplified the real case incorrectly, and therefore your code works for the simplified case but not for the real one. 

In any case, your explanation about the use of "Total <PRODUCTI_ID>" did help me. Hence, I have modified my initial code as follows: 

 - PRICE / Only({$<DATE={'$(=Min(DATE))'}>}  Total <PRODUCTI_ID> PRICE)

And the above code works exactly as expected. 

Once again, thank you for your help!