Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hello
I have two columns with many products:
Weight (g)
Price (£)
Product
Type
I'd like to calculate £/kg for a particular product and group which is easy in principle = £/kg = sum('Power BI'[Price per Unit])/sum('Power BI'[Weight])*1000
However, there are occassions where:
- Weight is "unidentified" (simply, it is a text I want to ignore)
- Price is "zero" and I don't want to do a calculation in that case
If in totals (e.g. at type level) there are products with 0 as price but with weight and they are taken into account in this calculation, , the calculation will be skewed.
What calculation should I use not to include rows where weight is not a text or error and price is not 0?
Thanks
Ewa
Solved! Go to Solution.
Hi @ewuchatka
Use the following formula in calculated columns
usefulweight = IF([Weight]="unidentified"||[Price]=0,BLANK(),[Weight])
usefulprice = IF([Price]=0||[Weight]="unidentified",BLANK(),[Price])
£/kg per product =
CALCULATE ( SUM ( Sheet7[usefulprice] ), ALLEXCEPT ( Sheet7, Sheet7[Product] ) )
/ CALCULATE (
SUM ( Sheet7[usefulweight] ),
ALLEXCEPT ( Sheet7, Sheet7[Product] )
)
* 1000
Best Regrads
Maggie
Hi @ewuchatka
Use the following formula in calculated columns
usefulweight = IF([Weight]="unidentified"||[Price]=0,BLANK(),[Weight])
usefulprice = IF([Price]=0||[Weight]="unidentified",BLANK(),[Price])
£/kg per product =
CALCULATE ( SUM ( Sheet7[usefulprice] ), ALLEXCEPT ( Sheet7, Sheet7[Product] ) )
/ CALCULATE (
SUM ( Sheet7[usefulweight] ),
ALLEXCEPT ( Sheet7, Sheet7[Product] )
)
* 1000
Best Regrads
Maggie
Hi,
Create a calculated column
Revised weight=IF(ISNUMBER('Power BI'[Weight]),'Power BI'[Weight],BLANK())
Now write this measure
£/kg = IFERROR(IF(sum('Power BI'[Price per Unit])/sum('Power BI'[Revised Weight])*1000=0,BLANK(),sum('Power BI'[Price per Unit])/sum('Power BI'[Revised Weight])*1000),BLANK())
Hope this helps.
Hi @ewuchatka,
You need to create a measure similar to this:
Total = CALCULATE ( SUM ( Table[Price per unit] ) / SUM ( Table[Weight] ) * 1000; Table[Price per unit] <> 0 || Table[Weight] <> "unindentified" )
Replace the columns by the ones you want to sum and filter.
Regards,
MFelix
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsCovering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
114 | |
101 | |
78 | |
75 | |
49 |
User | Count |
---|---|
145 | |
108 | |
107 | |
89 | |
61 |