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
ansa_naz
Continued Contributor
Continued Contributor

Calculated column - check values from related table with an IF statement

Hi all

 

I have the following two tables:

 

Jobs

JobID     Status

1            Complete

2            Complete

3            Open

4            Open

 

 

Tasks

JobID        Task          Status

1               T1            Complete

1               T2            Complete

1               T3            Open

2               T1            Complete

2               T2            Complete

3               T1            Open

3               T2            Open

4               T1            Open

4               T2            Complete

 

I want to create a calculated column (NewStatus) in the Jobs table, as follows:

 

IF Jobs[Status]="Complete" AND ALL RELATED Tasks[Status]="Complete" then "Complete"

ELSE IF Jobs[Status]="Complete" AND ALL RELATED Tasks[Status]<>"Complete" then "Labour Complete"

ELSE "Open"

 

So if I add the Jobs table to the report canvas as a table visual then I would get:

 

JobID      Status           NewStatus

1             Complete     Labour Complete

2             Complete     Complete

3             Open           Open

4             Open           Open

 

Any ideas how I can create this calculated column?

Many thanks for all help

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

@ansa_naz

 

Try this

 

=
VAR Condition1 =
    COUNTROWS ( RELATEDTABLE ( Tasks ) )
VAR Condition2 =
    CALCULATE ( COUNTROWS ( RELATEDTABLE ( Tasks ) ), Tasks[Status] = "Complete" )
RETURN
    SWITCH (
        TRUE (),
        AND ( [Status] = "Complete", Condition1 = Condition2 ), "Complete",
        AND ( [Status] = "Complete", Condition1 <> Condition2 ), "Labour Complete",
        "Open"
    )

Regards
Zubair

Please try my custom visuals

View solution in original post

2 REPLIES 2
Zubair_Muhammad
Community Champion
Community Champion

@ansa_naz

 

Try this

 

=
VAR Condition1 =
    COUNTROWS ( RELATEDTABLE ( Tasks ) )
VAR Condition2 =
    CALCULATE ( COUNTROWS ( RELATEDTABLE ( Tasks ) ), Tasks[Status] = "Complete" )
RETURN
    SWITCH (
        TRUE (),
        AND ( [Status] = "Complete", Condition1 = Condition2 ), "Complete",
        AND ( [Status] = "Complete", Condition1 <> Condition2 ), "Labour Complete",
        "Open"
    )

Regards
Zubair

Please try my custom visuals

Thanks so much @Zubair_Muhammad, works great! Will keep this DAX in my toolbox

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.