Forum Discussion
SumProduct with Power BI
Hi Team,
Please help me with SUMPRODUCT similar with excel in DAX measure... Below are my Actuals in Main Category and Lines. How to get weighted average using SUMPRODUCT logic in DAX command?
I want to get below highlight output using DAX command...
- Anonymous3 years ago
Hi Sandeep_PowerBI ,
In Power BI, you need to use unpivot and pivot for your data first, and then you can perform calculations.
After transformation, the data is as follows.
Create this measure:
Measure = VAR _table = SUMMARIZE ( 'Table', [Line], [ABC], [HMP], "Product", SUM ( 'Table'[ABC] ) * SUM ( 'Table'[HMP] ) ) RETURN DIVIDE ( SUMX ( _table, [Product] ), SUMX ( FILTER ( ALL ( 'Table' ), [Line] = MAX ( 'Table'[Line] ) ), [HMP] ) )Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
11 Replies
- AnonymousNot applicable
Hi Sandeep_PowerBI ,
In Power BI, you need to use unpivot and pivot for your data first, and then you can perform calculations.
After transformation, the data is as follows.
Create this measure:
Measure = VAR _table = SUMMARIZE ( 'Table', [Line], [ABC], [HMP], "Product", SUM ( 'Table'[ABC] ) * SUM ( 'Table'[HMP] ) ) RETURN DIVIDE ( SUMX ( _table, [Product] ), SUMX ( FILTER ( ALL ( 'Table' ), [Line] = MAX ( 'Table'[Line] ) ), [HMP] ) )Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Sandeep_PowerBIFrequent Visitor
Thank you Anonymous its working...
By,
Sandeep
- some_bih
Community Champion
Hi Sandeep_PowerBI as I wrote, I organize your excel data into different structure /unpivoting and basically rename your Actual to Weight to follow calculation logic.
In red below you can find example your and mine data.
- some_bih
Community Champion
Hi Sandeep_PowerBI the best would be to organize columns like amounts should be in one columns and weigths in another column (date is some third columns, if needed).
Check example for similar request https://community.fabric.microsoft.com/t5/Desktop/Weighted-Average-DAX/td-p/1661527
- Sandeep_PowerBIFrequent Visitor
Hi,
Thanks for response,
Actually separating in 3 columns is fine. Done in Transaformation unpivot. but, the same calculation is not matching to my requiremet. I want to calculate weighted Average value using DAX...
=SUMPRODUCT(D2:O2,D5:O5)/SUM(D2:O2) - using Excel
=SUMPRODUCT(HMP(D2:O2), ABC(D5:O5))/SUM(HMP(D2:O2))
Thanks,
Sandeep
- some_bih
Community Champion
Hi Sandeep_PowerBI if possible provide data not as picture so I can use it for testing measure to get your expected output
- some_bih
Community Champion
Hi Sandeep_PowerBI I organized your table as shown on first picture below, new calculate column
Product = ROUND(Sheet24[Amount]*Sheet24[Weight],2)and created 3 Measures below. On last picture there are results. I hope this help.
Amount_Line = SUM(Sheet24[Amount])Sum Product = SUM(Sheet24[Product])Weighted Avg =DIVIDE([Sum Product], [Amount_Line])Adjust Sheet24 for your table nameMy Excel from your data
- Sandeep_PowerBIFrequent Visitor
Hi some_bih
Thanks for providing solution but in my data, I dont have weight value columns f... Only 2 categories HMP and ABC values...
How did you calc weight (column F)
- Sandeep_PowerBIFrequent Visitor