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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
jitpbi
Post Patron
Post Patron

measure using If with multiple condition

Hi,

 

The following is the sample dataset of my actual dataset:

 

DeviceStatusDatetime
AGood10/23/2020 8:10:00 AM
AFaulty10/23/2020 4:15:00 PM
AGood10/24/2020 11:10:00 AM
BGood10/23/2020 8:10:00 AM
BGood10/23/2020 4:15:00 PM
BFaulty10/24/2020 11:10:00 AM
CFaulty10/23/2020 8:10:00 AM
CGood10/23/2020 4:15:00 PM
CFaulty10/24/2020 11:10:00 AM

 

I have to display those device's names which latest status is faulty.

I tried unsuccessfuly the below dax to create a measure:

faulty_device = if('Table'[Status]=" Faulty" && Table[DateTime]= max(Equipment[DateTime]), CONCATENATEX(Table,Table[Device], "is faulty device","No Device is faulty Currently"))
 
Please suggest how to achieve this.
 
Thanks
1 ACCEPTED SOLUTION
Anonymous
Not applicable

HI @jitpbi,

It seems like I forget to pack it with aggregate functions, please try this one if it works:

faulty_device =
VAR currSatatus =
    SELECTEDVALUE ( 'Table'[Status] )
VAR _lastDate =
    CALCULATE (
        MAX ( Equipment[DateTime] ),
        ALLSELECTED ( Table ),
        VALUES ( 'Table'[Device] )
    )
RETURN
    IF (
        currSatatus = " Faulty"
            && MAX( Table[DateTime] ) = _lastDate,
        CONCATENATEX ( VALUES ( Table[Device] ), [Device], "is faulty device" ),
        "No Device is faulty Currently"
    )

Regards,

Xiaoxin Sheng

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @jitpbi,

You can try to use the following measure formula if it works on your side:

faulty_device =
VAR currSatatus =
    SELECTEDVALUE ( 'Table'[Status] )
VAR _lastDate =
    CALCULATE (
        MAX ( Equipment[DateTime] ),
        ALLSELECTED ( Table ),
        VALUES ( 'Table'[Device] )
    )
RETURN
    IF (
        currSatatus = " Faulty"
            && Table[DateTime] = _lastDate,
        CONCATENATEX ( VALUES ( Table[Device] ), [Device], "is faulty device" ),
        "No Device is faulty Currently"
    )

If this not help, please share some dummy data to test coding formula.

Regards,

Xiaoxin Sheng

Hi @Anonymous ,

 

When trying to use the measure formula you shared, it is not accepting Table[DateTime] in the formula.

 

faulty_device =
VAR currSatatus =
SELECTEDVALUE ( 'Table'[Status] )
VAR _lastDate =
CALCULATE (
MAX ( Equipment[DateTime] ),
ALLSELECTED ( Table ),
VALUES ( 'Table'[Device] )
)
RETURN
IF (
currSatatus = " Faulty"
&& Table[DateTime] = _lastDate,
CONCATENATEX ( VALUES ( Table[Device] ), [Device], "is faulty device" ),
"No Device is faulty Currently"
)
 
Thanks
Anonymous
Not applicable

HI @jitpbi,

It seems like I forget to pack it with aggregate functions, please try this one if it works:

faulty_device =
VAR currSatatus =
    SELECTEDVALUE ( 'Table'[Status] )
VAR _lastDate =
    CALCULATE (
        MAX ( Equipment[DateTime] ),
        ALLSELECTED ( Table ),
        VALUES ( 'Table'[Device] )
    )
RETURN
    IF (
        currSatatus = " Faulty"
            && MAX( Table[DateTime] ) = _lastDate,
        CONCATENATEX ( VALUES ( Table[Device] ), [Device], "is faulty device" ),
        "No Device is faulty Currently"
    )

Regards,

Xiaoxin Sheng

CNENFRNL
Community Champion
Community Champion

@jitpbi , what the relationship with Table and Equipment (cardinality and direction)? As you know, relationship plays a critical role when authoring measures.

 

For the moment, I came up with a measure based on the single table like this,

Faulty Devices = 
VAR __tb =
    FILTER (
        FILTER (
            'Table',
            'Table'[Datetime]
                = CALCULATE ( MAX ( 'Table'[Datetime] ), ALLEXCEPT ( 'Table', 'Table'[Device] ) )
        ),
        'Table'[Status] = "Faulty"
    )
RETURN
    CONCATENATEX ( __tb, 'Table'[Device], UNICHAR ( 10 ) )

When dragged into a card viz, it returns

Screenshot 2020-10-26 002518.png

 


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Fowmy
Super User
Super User

@jitpbi 

Add the following measure;

Faulty Devices = 
VAR __STATUS =  LASTNONBLANKVALUE(Table5[Datetime],MAX(Table5[Status]))  RETURN
IF( __STATUS = "Faulty", __STATUS , BLANK() )

 

Fowmy_0-1603624102580.png

 

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn

 

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors