Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
thanhphongle
Creator II
Creator II

Comparing different price values from a single product

Hello Community,

this is my table

DateProductPrice
01.01.2016A100 €
01.01.2016A95 €
01.02.2016A95 €
01.03.2016A80 €
01.04.2016A80 €
01.01.2017A49 €
01.01.2016B1000 €
01.01.2016B950 €
01.02.2016B950 €
01.03.2016B800 €
01.04.2016B800 €
01.01.2017B300 €

is there a way to compare different price values from particular products? For example

if min(Price of a Product) is <= 50 % of max(Price of Product) , then sum(All min(Price of a Product) is <= 50 % of max(Price of Product))

->

Step 1

min[Product(A)] = 49€  is 50% smaller or more than 50% smaller than max[Product(A)]=100 €

min[Product(B)] = 300€  is 50% smaller or more than 50% smaller than max[Product(B)]=1000 €

Step 2

sum up all products  49€ + 300€ = 349€

I hope anyone can help me out here.

1 Solution

Accepted Solutions
Kushal_Chawda

This expression should work

=sum(aggr(if(min(Price)/max(Price)<=0.5,min(Price)),Product))

View solution in original post

9 Replies
prat1507
Specialist
Specialist

Hi

Where do you want to show the Final sum, do I need to add an extra column, or replace the min value for each product?

Regards
Pratyush

simotrab
Creator III
Creator III

Let's proceed with order, first we need the mins and the maxs:

min({$<Product={"A"}>}price)

min({$<Product={"B"}>}price)

max({$<Product={"A"}>}price)

max({$<Product={"B"}>}price)

So if I've understood well, maybe this could work (I've not tested yet).


if( min({$<Product={"A"}>}price)<=max({$<Product={"A"}>}price)*0.5,min({$<Product={"A"}>}price))

+

if( min({$<Product={"B"}>}price)<=max({$<Product={"B"}>}price)*0.5,min({$<Product={"B"}>}price))


I think that with a proper set analysis it could be better.

Kushal_Chawda

Data:

LOAD Date,

    Product,

    Price

FROM

[https://community.qlik.com/thread/269939]

(html, codepage is 1252, embedded labels, table is @1);

Left Join

LOAD Product,

    min(Price) as MinPrice,

    max(Price) as MaxPrice

Resident Data

Group by Product;

Final:

LOAD *,

    if(MinPrice/MaxPrice<=0.5,1) as Flag

Resident Data;

DROP Table Data;

Left Join(Final)

LOAD sum(DISTINCT MinPrice) as SumofAllProductPrice

Resident Final

where Flag=1;

Capture.JPG

thanhphongle
Creator II
Creator II
Author

Hello Simone,

thank you for your help. The solution should consider all kind of products. In my example I listed only product A and B. But for the case I have more products the solution should sum up all product to the mentioned conditions. So I think it would be really time-consuming

thanhphongle
Creator II
Creator II
Author

Hello Pratyush,

I' d like to show the sum in a textbox. The solution should consider all kind of products not only A and B. The product A and B was just an example.

thanhphongle
Creator II
Creator II
Author

Hello Kushal,

I'm about to try your solution. Is there another way to solve my problem instead of manipulating the script?

Kushal_Chawda

This expression should work

=sum(aggr(if(min(Price)/max(Price)<=0.5,min(Price)),Product))

thanhphongle
Creator II
Creator II
Author

This is expression works great!!

Thank you very much!!

Kushal_Chawda

Glad that it worked