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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
jacostabarbosa
Frequent Visitor

Dax to calculate MIN value excluding blank cells

Hi there, i have a table with two columns MO & CO. Each column has a number of days and sometimes the cell is empty wich is ok. What i have been trying to achieve is to get the minimum value of both columns using the dax formula MIN(). However, Power BI assume that if the cell is empty it is equal to zero which results in a minimum value of zero. NOTE: Both columns MO and CO are measures. 

I Have been trying to use the conditional IF to find the way that if a cell is BLANK return the other value and if bth cells are BLANK then zero or empty as a result is OK. I appreciate your help

 

MOCOCurrent ResultExpected Result
250300

250

250
 45045
15 015
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@jacostabarbosa , try one of the two

 

MIn(coalesce([MO],[CO]),coalesce([CO],[MO]))

 

 

if(coalesce([MO],[CO]) <coalesce([CO],[MO]), coalesce([MO],[CO]), coalesce([CO],[MO]) )

View solution in original post

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

I tried to create a sample pbix file like below. I hope you can get an idea to apply it to your model.

 

Picture1.png

 

Expected result: =
VAR MOtable =
    ADDCOLUMNS ( VALUES ( Data[ID] ), "@result", [Mo measure:] )
VAR COtable =
    ADDCOLUMNS ( VALUES ( Data[ID] ), "@result", [Co measure:] )
VAR newtable =
    FILTER ( UNION ( MOtable, COtable ), [@result] <> BLANK () )
RETURN
    IF ( HASONEVALUE ( Data[ID] ), MINX ( newtable, [@result] ) )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


amitchandak
Super User
Super User

@jacostabarbosa , try one of the two

 

MIn(coalesce([MO],[CO]),coalesce([CO],[MO]))

 

 

if(coalesce([MO],[CO]) <coalesce([CO],[MO]), coalesce([MO],[CO]), coalesce([CO],[MO]) )

@amitchandak thanks so much for your help. The first code was the one i used and worked perfectly

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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