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

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
ksharpes
Creator
Creator

Set Analysis using formula

Hello.

I have the following formula to work out the Customer that has the lowest price "FirstSortedValue(DISTINCT Customer , [Unit Price])"

Now I would like to work out how much that Customer sold for the product in question.

I thought it would look something like 

Sum({<Customer ={'=FirstSortedValue(DISTINCT Customer , [Unit Price])'}>} SALES)

I've tried single and Double quotes, with or without "=" but its not working any suggestions?

1 Solution

Accepted Solutions
lironbaram
Partner - Master III
Partner - Master III

hi 

because you need to find the lowest customer for several products , you can't use set analysis 

set analysis returns one value for the whole app, and not a value per row 

this is a formula to find the customer with the min price for each product 

FirstSortedValue(aggr(Customer,Customer,CommonName),aggr(minstring(UnitPrice),Customer,CommonName))

you need to adjust the field names for your data 

this the amount the customer above has purchased 

FirstSortedValue(aggr(sum(SALES),Customer,CommonName),aggr(minstring(UnitPrice),Customer,CommonName))

View solution in original post

9 Replies
lironbaram
Partner - Master III
Partner - Master III

hi 

try this formula 

Sum({<Customer ={"$(=FirstSortedValue(DISTINCT Customer , [Unit Price]))"}>}[Sales Amount])

ksharpes
Creator
Creator
Author

So i think i may have missed out an important bit of information as it isn't giving me the result I was looking for.

 

I have am looking for the lowest price for a particular product field name is called [Common Name] 

FirstSortedValue(DISTINCT BU , [Unit Price])

The above formula does give me the right answer however if i put it within a formula "Sum({<Customer ={"$(=FirstSortedValue(DISTINCT Customer , [Unit Price]))"}>}SALES)" if then gives me the Customer with the lowest price overall instead of that particular Product so it sums the sales for that customer and not the customer with the lowest price for that product.

sunny_talwar

May be this

Sum(Aggr(
    If([Unit Price] = Min(TOTAL <Product> [Unit Price]), Sum([Sales Amount]))
, Product, Customer))
ksharpes
Creator
Creator
Author

No that didn't work

sunny_talwar

Would you be able to share a sample or sample data and the expected output to help you better?

Rohan
Partner - Specialist
Partner - Specialist

Hello, can you try this formula & check if this works for you ?

min({<Customer ={"$(=FirstSortedValue(DISTINCT Customer , [Unit Price]))"}>}[Unit Price])

ksharpes
Creator
Creator
Author

Sample data below

There would be multiple products:

CustomerProduct CodeProduct TypeCommon NameQUANTITYSALES Unit Price 

Cust 1abc11Product 172111.5 €           1.55
Cust 1 1Product 13655.75 €           1.55
Cust 1abc11Product 1432669 €           1.55
Cust 1abc11Product 172111.5 €           1.55
Cust 1abc11Product 13655.75 €           1.55
Cust 1abc11Product 172111.5 €           1.55
Cust 1abc11Product 13656.93 €           1.58
Cust 1abc11Product 16481024.74 €           1.58
Cust 1abc11Product 13656.93 €           1.58
Cust 2abc11Product 23659.04 €           1.64

 

I would like to show something like the below (the Sales of min price seller formula is what I'm having trouble with)

 

Common product nameTotal Product salesCustomer with lowest min priceSales of min price sellerCustomer with lowest avg priceSales of avg price seller
Product 1           2,313 € Cust 1            2,254 € Cust 2            2,254 €
Product 2         53,983 € Cust 2                59 € Cust 1                 59 €
Product 3         14,788 € Cust 2          10,884 € Cust 1          10,884 €
lironbaram
Partner - Master III
Partner - Master III

hi 

because you need to find the lowest customer for several products , you can't use set analysis 

set analysis returns one value for the whole app, and not a value per row 

this is a formula to find the customer with the min price for each product 

FirstSortedValue(aggr(Customer,Customer,CommonName),aggr(minstring(UnitPrice),Customer,CommonName))

you need to adjust the field names for your data 

this the amount the customer above has purchased 

FirstSortedValue(aggr(sum(SALES),Customer,CommonName),aggr(minstring(UnitPrice),Customer,CommonName))

ksharpes
Creator
Creator
Author

Thanks for the solution, also thanks for the explanation, I was unaware of that limitation with Set Analysis.