cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Diego-mx
Advocate I
Advocate I

How to summarize logicals in IF condition?

Hey guys, I am breaking my head for something very simple.  

I'm calculating the total margin in a Cars table.  In a simple context, things would look like this, 

 

CarsMargin_ideal = CALCULATE( 1 - SUM([purchase_price])/SUM(selling_price), 
FILTER( Cars, [was_sold] == 1) )

 

The problem is some entries don't have prices, which in most cases don't matter because they won't be added.  
But in special filters, those are all the cars so it looks as though the margin is 100%.  

The way I'd want to fix this is: 

 

CarsMargin_ideal = CALCULATE( IF( AND( SUM([was_sold]>0), NOT(ALL(ISBLANK([selling_price]))) ),
1 - SUM([purchase_price])/SUM([selling_price]), BLANK( )),
FILTER( Cars, [was_sold] == 1) )

 

One would notice that the function ALL doesn't refer to a logical ALL, but something else.  And everywhere I look I cannot find a way to compare all entries in what results a logical vector.  

Simplifying the question, how do I go about the condition in this piece of logic:  

 

CALCULATE( IF( any_or_all( logical_vector ),
calculation, blank), filters )

 

Thanks, 

 

 

 

1 ACCEPTED SOLUTION
v-yuezhe-msft
Microsoft
Microsoft

@Diego-mx ,

Please check if the following DAX works. If not, please share sample data of your table and post expected result here.

IF( AND( SUM([was_sold]>0), NOT((ISBLANK([selling_price]))),CALCULATE( 1 - SUM([purchase_price])/SUM(selling_price), 
    FILTER( Cars, [was_sold] == 1) ),BLANK())



Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-yuezhe-msft
Microsoft
Microsoft

@Diego-mx ,

Please check if the following DAX works. If not, please share sample data of your table and post expected result here.

IF( AND( SUM([was_sold]>0), NOT((ISBLANK([selling_price]))),CALCULATE( 1 - SUM([purchase_price])/SUM(selling_price), 
    FILTER( Cars, [was_sold] == 1) ),BLANK())



Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors