Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
ewuchatka
Helper II
Helper II

If two conditions are met then use measure

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

 

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

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

6.png

 

Best Regrads

Maggie

View solution in original post

3 REPLIES 3
v-juanli-msft
Community Support
Community Support

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

6.png

 

Best Regrads

Maggie

Ashish_Mathur
Super User
Super User

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.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
MFelix
Super User
Super User

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


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.