Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
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,
Solved! Go to Solution.
@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
@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
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
User | Count |
---|---|
144 | |
73 | |
64 | |
52 | |
51 |
User | Count |
---|---|
208 | |
91 | |
62 | |
59 | |
56 |