cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
coding
Frequent Visitor

Get the max of a value based on a category and date

Hi, 

I've a table that shows me the category by state and the start and end date:

coding_0-1670006514422.png

 

and I'm trying to create a conditional column that returns the maximum of each category and status.

 

I tried to create the column in M

 

Logic= if [Status] = "InProgress" and [Start] = List.Max(#"Sorted Rows1"[Start]) and [End] = #datetime(2999, 12, 31, 0, 0, 0) then 2 else if [Status] = "Succeeded" then 1 else 0

 

​​and it is working correctly except for the case of CategoryG which should only return the value of "2" from the Logic column, and instead it is returning the maximum of the Succeeded status and the InProgress status, where it should only show the InProgress status because it has a longer start date.

coding_1-1670006799161.png

I also tried creating in DAX but got the same result (the StartDate is selected as "Earliest" and the EndDate and End Test as "Latest"):

coding_0-1670009332107.png

 

 

Flag DAX = SWITCH( TRUE (),
       'Table'[Start]= MAX ( 'Table'[Start] )
        && 'Table'[End Test] = BLANK ()
        && 'Table'[Status] = "InProgress", 2,
        'Table'[Status] = "Failed", 1,
        'Table'[Start]= LASTNONBLANK(  'Table'[Start],1 )
        && 'Table'[Status] = "Succeeded"  && 'Table'[End Test] <> BLANK (), 3,
        0
  )

 


Desired output:

coding_1-1670009484626.pngAny idea how to solve this ? 

Thanks and kind regards. 

1 ACCEPTED SOLUTION
v-jialluo-msft
Community Support
Community Support

Hi  @coding ,

 

You can try this measure:

Flag DAX = SWITCH( TRUE (),
       MAX('Table'[Start])= CALCULATE(MAX('Table'[Start]),ALL('Table'))
        && MAX('Table'[End Test]) = BLANK ()
        && MAX('Table'[Status]) = "InProgress", 2,
        MAX('Table'[Status]) = "Failed", 1,
        MAX('Table'[Start])=CALCULATE(LASTNONBLANK('Table'[Start],1),ALL('Table'))
        && MAX('Table'[Status]) = "Succeeded"  && MAX('Table'[End Test]) <> BLANK (), 3,
        0
  )

If that's not what you need, provide sample files.

 

Best Regards,
Gallen Luo
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

2 REPLIES 2
v-jialluo-msft
Community Support
Community Support

Hi  @coding ,

 

You can try this measure:

Flag DAX = SWITCH( TRUE (),
       MAX('Table'[Start])= CALCULATE(MAX('Table'[Start]),ALL('Table'))
        && MAX('Table'[End Test]) = BLANK ()
        && MAX('Table'[Status]) = "InProgress", 2,
        MAX('Table'[Status]) = "Failed", 1,
        MAX('Table'[Start])=CALCULATE(LASTNONBLANK('Table'[Start],1),ALL('Table'))
        && MAX('Table'[Status]) = "Succeeded"  && MAX('Table'[End Test]) <> BLANK (), 3,
        0
  )

If that's not what you need, provide sample files.

 

Best Regards,
Gallen Luo
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

lbendlin
Super User
Super User

Please provide sanitized sample data that fully covers your issue.
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors