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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Anonymous
Not applicable

Retrieve a text value in one column based on MAX in another

I have the following table. There are 8 machine ID's. What I need is a table which shows the color of the maximum last status date/time. So for machine 1 this is the color red, for machine 2 color red, machine 3 color orange...etc. I tried selected value and lookup value together with maximum last status date / time, but don't get the right solution. Please advise! Thanks in advance.

 

 

Superdeathmonke_0-1598360598856.png

 

1 ACCEPTED SOLUTION

@Anonymous - Updated. Updated the PBIX as well, attached.

 

Measure 24 = 
  VAR __Color = MAX('Table (24)'[Machine Status])
  VAR __Laststatus = MAX('Table (24)'[Laststatus])
  VAR __Table = SELECTCOLUMNS(SUMMARIZE(FILTER(ALL('Table (24)'),[Laststatus]=__Laststatus),[Machine ID],"__Last",MAX('Table (24)'[Laststatus])),"__Machine",[Machine Id],"__Last",[__Last])
  VAR __Table1 = 
    ADDCOLUMNS(
      __Table,
      "__Status",
        MAXX(
          FILTER('Table (24)','Table (24)'[Machine ID]=[__Machine] && 'Table (24)'[Laststatus]=[__Last]),
          [Machine Status]
        )
     )
RETURN
  COUNTROWS(FILTER(__Table1,[__Status] = __Color))

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

18 REPLIES 18
amitchandak
Super User
Super User

@Anonymous , use this with machine id in a visual

lastnonblankvalue(table[laststatus], max(table[machinestatus]))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Greg_Deckler
Community Champion
Community Champion

@Anonymous - You could create a measure like the following:

 

Measure = 
  VAR __Machine = MAX('Table'[Machine ID])
  VAR __Date = MAXX(FILTER(ALL('Table'),[Machine ID] = __Machine),[Laststatus])
RETURN
  MAXX(FILTER(ALL('Table'),[Machine ID] = __Machine && [Laststatus] = __Date),[Machine_status])

This is basically Lookup Min/Max - https://community.powerbi.com/t5/Quick-Measures-Gallery/Lookup-Min-Max/m-p/985814#M434 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler thank you greg, i amtrying to put this into a chart that looks at number of machine IDs per machine status. Issue is i am guessing i can't do this with that? as i need the measur eto be on the axis

@Anonymous - In general, to use a measure in that way, you need to use the Disconnected Table Trick as this article demonstrates: https://community.powerbi.com/t5/Community-Blog/Solving-Attendance-with-the-Disconnected-Table-Trick/ba-p/279563

 

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler sorry that was bad english, i mean in a graph i just want to see how many of each level there are

@Anonymous - OK, maybe this:

Measure = 
  VAR __Color = MAX('Table'[Machine_status])
  VAR __Table = SUMMARIZE('Table',[Machine ID],"__Last",MAX([Laststatus]))
  VAR __Table1 = ADDCOLUMNS(__Table,"__Status",MAXX(FILTER('Table','Table'[Machine ID]=[Machine ID] && 'Table'[Laststatus]=[__Last])
RETURN
  COUNTROWS(FILTER(__Table1,[__Status] = __Color))


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler thank you again, i am getting the follwoing error;

Superdeathmonke_0-1598363950356.png

Superdeathmonke_1-1598363950562.png

not sure if i am missing a ) or something but when it hits RETURN its giving me the red underlining. To add this to a bar chart would i be able to just use the axis as machine status then this measure as the count?

 

 

@Anonymous - Yeah, there is a missing ) and other issues. This is what happens when I code without testing. Which is why it is super helpful to post sample data as text instead of images...

 

Measure = 
  VAR __Color = MAX('Table'[Machine_status])
  VAR __Table = SUMMARIZE('Table',[Machine ID],"__Last",MAX([Laststatus]))
  VAR __Table1 = 
    ADDCOLUMNS(
      __Table,
      "__Status",
        MAXX(
          FILTER('Table','Table'[Machine ID]=[Machine ID] && 'Table'[Laststatus]=[__Last]),
          [Status]
        )
     )
RETURN
  COUNTROWS(FILTER(__Table1,[__Status] = __Color))

 

  



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler again thank you for the support, when i put the machine status into the axis then this into value i get the following;

Superdeathmonke_0-1598365839675.png

@Anonymous - Hard to tell but seems like somewhere along the line you are trying to compare Laststatus and Machine_status perhaps. Let me double-check. Can you post some sample data as text so that I can copy and paste it into a PBIX file and actually do the calculation? Then I can upload the PBIX.

 

Measure = 
  VAR __Color = MAX('Table'[Machine_status])
  VAR __Table = SUMMARIZE('Table',[Machine ID],"__Last",MAX([Laststatus]))
  VAR __Table1 = 
    ADDCOLUMNS(
      __Table,
      "__Status",
        MAXX(
          FILTER('Table','Table'[Machine ID]=[Machine ID] && 'Table'[Laststatus]=[__Last]),
          [Machine_status]
        )
     )
RETURN
  COUNTROWS(FILTER(__Table1,[__Status] = __Color))

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

thank you @Greg_Deckler the laststaus will also be a filter on the page so if i filtered to 1 date it will be th elatest for that date selected , please see below sample data;

 

Machine IdLaststatusMachine Status
108/01/2020Error
109/01/2020Green
110/01/2020Orange
111/01/2020Red
208/01/2020Error
209/01/2020Green
210/01/2020Orange
211/01/2020Red
308/01/2020Error
309/01/2020Green
310/01/2020Orange
311/01/2020Green
408/01/2020Green
409/01/2020Orange
410/01/2020Red
411/01/2020Error
608/01/2020Red
609/01/2020Orange
610/01/2020Green
611/01/2020Orange

@Anonymous  - OK, sooooo much easier to debug. PBIX is attached, you want Table (24), Measure 24.

Measure 24 = 
  VAR __Color = MAX('Table (24)'[Machine Status])
  VAR __Table = SELECTCOLUMNS(SUMMARIZE(ALL('Table (24)'),[Machine ID],"__Last",MAX('Table (24)'[Laststatus])),"__Machine",[Machine Id],"__Last",[__Last])
  VAR __Table1 = 
    ADDCOLUMNS(
      __Table,
      "__Status",
        MAXX(
          FILTER('Table (24)','Table (24)'[Machine ID]=[__Machine] && 'Table (24)'[Laststatus]=[__Last]),
          [Machine Status]
        )
     )
RETURN
  COUNTROWS(FILTER(__Table1,[__Status] = __Color))

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler  this does work but doesnt when i try filter dates, so if i filter using the laststatus this doesnt show anything in the table i would expect the measure to recalculate to say this is now the latest date it could be

@Anonymous - Updated. Updated the PBIX as well, attached.

 

Measure 24 = 
  VAR __Color = MAX('Table (24)'[Machine Status])
  VAR __Laststatus = MAX('Table (24)'[Laststatus])
  VAR __Table = SELECTCOLUMNS(SUMMARIZE(FILTER(ALL('Table (24)'),[Laststatus]=__Laststatus),[Machine ID],"__Last",MAX('Table (24)'[Laststatus])),"__Machine",[Machine Id],"__Last",[__Last])
  VAR __Table1 = 
    ADDCOLUMNS(
      __Table,
      "__Status",
        MAXX(
          FILTER('Table (24)','Table (24)'[Machine ID]=[__Machine] && 'Table (24)'[Laststatus]=[__Last]),
          [Machine Status]
        )
     )
RETURN
  COUNTROWS(FILTER(__Table1,[__Status] = __Color))

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Anonymous - Suspense is killing me, did we finally get to the answer?!?!??



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler it did work but had the issue of when putting into a table it was showing duplicate levels for some machine IDs which it hsould be showing the latest but i managed to do it via;

 

Machine Count by Last Status =
VAR MaxDateTimePerMachine =
    ADDCOLUMNS (
        VALUES ( YourTable[Machine ID] ),
        "@MaxDateTime",
            CALCULATE (
                MAX ( YourTable[Laststatus] ),
                // Remove status filter because status is on chart axis
                REMOVEFILTERS ( YourTable[Machine_status] )
            )
    )
VAR MaxDateTimePerMachineLineage =
    TREATAS ( MaxDateTimePerMachine, YourTable[Machine ID], YourTable[Laststatus] )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( YourTable[Machine ID] ),
        MaxDateTimePerMachineLineage
    )

 

@Anonymous - Glad we were able to get there in the end!



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler thank you for all your help as always

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.