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

Weighted Distribution

Hi All,

I have a client requirement to calculate the weighted Distribution of an Product.

Weighted Distribution -Sum of Sales of Stores selling the product by the Total Sales of all Stores.


We have to breakdown the Weighted Distribution on Products but I am struck in the expression for Numerator i.e. Sum of Sales of Stores selling the product.


I am able to write the expression to calculate the weighted Distribution for consolidated Product but when I have to breakdown the same to show the Weighted Distribution for each Product its giving me the Sum of sales of Product not the sum of Sales of Stores selling the product.

Below is the expression for WD for consolidated Products, which is working fine:


Numerator - sum({1<PickLevel = {"Total Store"},$(=$(vSetAnalysisCurrentPeriod)),storeid={$(=chr(39) & concat(distinct storeid,chr(39)&','&chr(39)) & chr(39))}>} $(=$(Sales))))


Denominator - SUM({< PickLevel = {"Total Store"}, >} $(=$(Sales)))


     

ProductStoreidPicklevelSalesNo Prod cat
A1Total Stores10All Shop
B2Total Stores20All Shop
C3Total Stores34Non Shop
A4Total Stores36All Shop
B5Total Stores65All Shop
D6Total Stores456All Shop
A7Total Stores64Non Shop
D8Total Stores34All Shop


Can someone help me to write the expression.

5 Replies
sunny_talwar

Not entirely sure I understand, but may be try this

Sum({1<PickLevel = {"Total Store"}, $(=$(vSetAnalysisCurrentPeriod)), storeid = p(storeid)>} $(=$(Sales))))

ajitkjain
Partner - Contributor
Partner - Contributor
Author

Hi Sunny,

Thanks for the quick respond for my query, but is still not fulfilling my query.

Please refer the below sample data:

ProductStoreSales
A110
A220
A330
B140
B250
C360
C470
D380
D590

 

StoreSales
11000
25000
3800
41500
52000
Sum10300

So now WD for Product A will be (2800/10300)*100 = 66.019%.

I had written the expression as

sum({store =<P({1<prod = {'A'}>}store)>}Sales) - But its not giving me correct output.

Could you please help me to help me what is wrong in this expression or with the new expression.

sunny_talwar

I am not sure I understand... why do you have Sales in both the tables? How do you get 2800 from the data you have provided?

ajitkjain
Partner - Contributor
Partner - Contributor
Author

Second Table contains the Sales of different stores and the first table contains the Sales of Product sold on different stores.

Please rename the column Sales from 2nd Table as "StoreSales"

Let suppose I have to calculate the weighted distribution for Product A

WD of Prod A = Sum of sales of all the stores where product A is being sold / sum of sales of all the stores.

So, in my data Product A is being sold on 3 stores i.e. 1,2,3 so Numerator value consists of the sum of sales of these 3 stores where product A is being sold.

ajitkjain
Partner - Contributor
Partner - Contributor
Author

I found the solution to my problem. Thank you for suggestions.