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
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

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

5 REPLIES 5
v-shex-msft
Community Support
Community Support

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hi @v-shex-msft ,

 

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

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
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
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.