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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
prj102
Helper I
Helper I

Calculated column based on multiple rows and checking results.

I'm looking for a calculated column function that will help me determine an overall status based on multiple rows of data.  

My data looks something like this and I am looking to create the "Calculated Overall Status" column:

 

NameTypeStatusCalculated Overall Status
PT001gFailedFailed
PT001sPassedFailed
PT002gPassedPassed
PT002sPassedPassed
PT003gPassedWarning
PT003sWarningWarning

 

If a "Name" shows up more than once in the data, I want to look at all the statuses and mark them as "Passed" if they all passed, "Falied" if any of the statuses failed and Warning if there is a warning in any status.

 

If I'm not thinking of this correctly please send me in the right direction

 

1 ACCEPTED SOLUTION

@prj102 

 

You may try the DAX below.

Column =
SWITCH (
    TRUE (),
    ISEMPTY (
        FILTER (
            'Table',
            'Table'[Name] = EARLIER ( 'Table'[Name] )
                && 'Table'[Status] <> "Passed"
        )
    ), "Passed",
    NOT (
        ISEMPTY (
            FILTER (
                'Table',
                'Table'[Name] = EARLIER ( 'Table'[Name] )
                    && 'Table'[Status] = "Failed"
            )
        )
    ), "Failed",
    NOT (
        ISEMPTY (
            FILTER (
                'Table',
                'Table'[Name] = EARLIER ( 'Table'[Name] )
                    && 'Table'[Status] = "Warning"
            )
        )
    ), "Warning"
)

 

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
TomMartens
Super User
Super User

Hey,

 

try this DAX statement:

Column = 
var _name = 'Table'[Name]
var theString = CONCATENATEX(FILTER(ALL('Table') , 'Table'[Name] = _name) , 'Table'[Status] , "|" , 'Table'[Status] , ASC)
return
SWITCH(
    TRUE()
    , PATHCONTAINS(theString , "Failed") , "Failed"
    , PATHCONTAINS(theString , "Warning") , "Warning"
    , "Passed"
)

This calculated column looks like your expected result:

image.png

What the DAX does is this:

  1. it stores the current value of the column Name to the variable _name
  2. it creates a string of all the status values for one Name separated by "|", this allows interpreting the string as path
  3. using SWITCH to check the occurence of Failed or Warning inside the "Path"

Just switch the order of the rows

PATHCONTAINS( ... , "Failed") , "Failed"

PATHCONTAINS( ... , "WArning") , "Warning"

if "Warning" tops "Failed".

Hopefully this is what you are looking for.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

I see that your solution is working on the sample data and I even recreated it working myself but its not working on our production data.  Can't explain why at this point...  In the real data, every row is reporting Passed so I can only assume its defaulting to that.  More to come 

@prj102 

 

You may try the DAX below.

Column =
SWITCH (
    TRUE (),
    ISEMPTY (
        FILTER (
            'Table',
            'Table'[Name] = EARLIER ( 'Table'[Name] )
                && 'Table'[Status] <> "Passed"
        )
    ), "Passed",
    NOT (
        ISEMPTY (
            FILTER (
                'Table',
                'Table'[Name] = EARLIER ( 'Table'[Name] )
                    && 'Table'[Status] = "Failed"
            )
        )
    ), "Failed",
    NOT (
        ISEMPTY (
            FILTER (
                'Table',
                'Table'[Name] = EARLIER ( 'Table'[Name] )
                    && 'Table'[Status] = "Warning"
            )
        )
    ), "Warning"
)

 

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.