Forum Discussion
Aggregation using Sumproduct() in Power BI
I'm working on creating a Power BI report to emulate an existing Excel report. In the excel report, they are using the sumproduct() function to calculate and aggregate the data to determine MyCompany's price index on the product and market level. The data set is as follows:
1st Lev aggregation = sumproduct(1st Lev Units,1st Lev Index)/sum(1stLev Units)
Rival1 & 2= Provided
Item = Provided
1st Level Units = Provided
1st Level Index = Provided
1st Level Line Weight = 1st Level Units * 1st Level Index for Rival1 and Rival2
1st Level Weighted Average = Sum 1st Level Line Weight / Sum 1st Level Units
2nd Lev aggregation = sumproduct(2nd Lev Units, 2nd Lev Index)/sum(2ndLev Units)
MyCompany = Provided
1st Level Weighted Average = Calculated (by Rival#)
2nd Level Line Weight = 1st Level Weighted Average (by Rival#)* MyCompany Units
2nd Level Weighted Average = Sum 2nd Level Line Weight / Sum MyCompany Units
Company Item Units Index 1st Lev Line Wt 1st Sum Line Wt 1st Sum Units 1st Lev Wt Ave
MyCompany A85 120
Rival1 B23 150 0.8506 127.59
Rival1 B44 73 0.9584 69.9632
Rival1 B75 22 0.8756 19.2632 216.82 245 0.8850
Rival2 C18 2 1.0596 2.1192 2.1192 2 1.0596
MyCompany A66 85
Rival1 B23 150 0.8506 127.59
Rival1 B44 73 0.9584 69.9632
Rival1 B99 15 1.0468 15.702 213.82 238 0.8960
Rival2 C18 2 1.0596 2.1192 2.1192 2 1.0596
MyCompany A77 65
Rival1 B44 73 0.9584 69.9632
Rival1 B99 15 1.0468 15.702 85.665 88 0.9735
Rival2 C18 2 1.0596 2.1192
Rival2 C33 120 0.9951 119.412 121.53 1
Company Item Units Rival Index 2nd Lev Line Wt 2nd Sum Line Wt 2nd Sum Units 2nd Lev Wt Average
MyCompany-Rival1 A85 120 0.8850 106.20
MyCompany-Rival1 A66 85 0.8960 76.16
MyCompany-Rival1 A77 65 0.9735 63.28
MyCompany-Rival2 A85 120 1.0596 127.15
MyCompany-Rival2 A66 85 1.0596 90.07
MyCompany-Rival2 A77 65 0.9962 64.75
MyCompany-Rival1 245.63 270 0.9098
MyCompany-Rival2 281.97 270 1.0443
MyCompany 527.6 540 0.9770
I am able to complete the 1st level aggregation process, however I am having trouble completing the 2nd level aggregation. My problem is finding a way to aggregate the rival index (1st Lev Weighted Average) to the 2nd level to complete the calculations. If you know of a way to get this completed, I would greatly appreciate the advice,
Indraneel Dutt
3 Replies
- SivaManiResident Rockstar
Anonymous,
Check this function - https://docs.microsoft.com/en-us/dax/sumx-function-dax
SUMX(<table>, <expression>)
<expression> -> you can add calculations such as 1st Level Units * 1st Level Index for Rival1 and Rival2
Hope it will help you!
- amitchandakSuper User
You can use sumx to have mutiplcation od measures. Refer to this post to have different formula at different level
https://community.powerbi.com/t5/Desktop/Measure-logic-for-different-hierarchy-level/td-p/699606
Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
https://community.powerbi.com/t5/Community-Blog/Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners/ba-p/890814
https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-trend/ba-p/882970
https://community.powerbi.com/t5/Community-Blog/Power-BI-Working-with-Non-Standard-Time-Periods/ba-p/881739
https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601- AnonymousNot applicable
Hello all,
Thank you for your suggestions to use sumx() as a means to generate the needed subtotals for my exercise. I did have one follow up question, have either of you experienced difficulty of performing a sumx() function using input from a column generated by a sumx() measure?
In my example, I'm trying to generate the value for the 2nd Sum of MyCompany Line Weight using the sumx() function, but Power BI is not recognizing the MyCompany Line Weight column. Any suggestions?
Indraneel Dutt