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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
lathaaa
Frequent Visitor

IF condition based on two columns

Hi All, need help on writing DAX

the logic should be if that particular ID is only Failed - 0, only Success - 1, Success & failed - 2, Success & Failed & reprocess - 3

the expected column should be like below image.

lathaaa_0-1659518505907.png

 

1 ACCEPTED SOLUTION

@AntonioM , got the solution by using this DAX code

var statuses = CALCULATETABLE(VALUES(T_Invoice[Check]),T_Invoice[Report_ID] = EARLIER(T_Invoice[Report_ID]), ALL(T_Invoice) )

Thank you 🙂

View solution in original post

6 REPLIES 6
lathaaa
Frequent Visitor

@AntonioM , I tried with the code which you provided, expected column  is giving the result based on only status, but the condition is also to check based on ID & Status

 

Ex- if ID is 456 and failed, success & reprocess then 3

@lathaaa Could you show me what you're getting when you've tried that? The line

var statuses = CALCULATETABLE( VALUES('Table'[Status]), ALL('Table'[Status]) )

should keep the filter on ID and check for all statuses. Do you have any other other columns in the table?

@AntonioM , got the solution by using this DAX code

var statuses = CALCULATETABLE(VALUES(T_Invoice[Check]),T_Invoice[Report_ID] = EARLIER(T_Invoice[Report_ID]), ALL(T_Invoice) )

Thank you 🙂

@AntonioM  Yes, the table has other columns
the code i have tried - 
Column_check =
var statuses = CALCULATETABLE( VALUES(T_Invoice[Check]), ALL(T_Invoice[Check]) )
return
SWITCH(
TRUE(),
CONTAINS(statuses,T_Invoice[Check], "True") && CONTAINS(statuses,T_Invoice[Check], "False") && CONTAINS(statuses,T_Invoice[Check], "blank"),
3,
CONTAINS(statuses,T_Invoice[Check], "True") && CONTAINS(statuses,T_Invoice[Check], "blank"),
2,
CONTAINS(statuses,T_Invoice[Check], "True"),
1,
CONTAINS(statuses,T_Invoice[Check], "blank"),
0
)

 

when i try to filter on one ID and check for status, column check is the result but expected result should be as it is "True" & "blank" for that ID , it has to show 2 instead of 0 & 1

lathaaa_0-1659536584717.png

thank you

@amitchandak @Greg_Deckler , could you please help me on this DAX

AntonioM
Solution Sage
Solution Sage

Please give this a try

Column = 
var statuses = CALCULATETABLE( VALUES('Table'[Status]), ALL('Table'[Status]) )
return
SWITCH(
    TRUE(),
    CONTAINS(statuses,'Table'[Status], "reprocess") && CONTAINS(statuses,'Table'[Status], "Failed") && CONTAINS(statuses,'Table'[Status], "Success"),
    3,
    CONTAINS(statuses,'Table'[Status], "Failed") && CONTAINS(statuses,'Table'[Status], "Success"),
    2,
    CONTAINS(statuses,'Table'[Status], "Success"),
    1,
    CONTAINS(statuses,'Table'[Status], "Failed"),
    0
)

Which will give you

AntonioM_0-1659531037272.png

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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