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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
BruceNewsom
Regular Visitor

Last status change in period

Hi,

I have a history table of RAG statuses and I want to report the last status recorded in each period. (or prior if no status recorded in the period). [RAG] is a text field containing "R", "A", or "G".

 

I am using the following measure:

Last_RAG = Calculate(max(History[RAG]), REMOVEFILTERS(),History[Modified Date] <= SELECTEDVALUE('Calendar'[Period]) , History[Project_Id] = SELECTEDVALUE('Project Status'[ID]))
 
But of course this gives me the maximum value recorded so selects R rather than A or G if more than one status happens to be recorded in the same period.  I want the last status that was reported up to the end of the period.

After reading through posts I found this thread
 with a reply by @Greg_Deckler that looked like it would work but doesn't seem to do it for me.  Here's how I modified the code:
Last_RAG =
    VAR _LastDate =
    CALCULATE(
        MAXX(
            FILTER('Calendar',[Date]<= SELECTEDVALUE('Calendar'[Period])),
            [Date]
        )
        ,REMOVEFILTERS())
        VAR _Result = MINX(FILTER(History, [Modified Date] = _LastDate), History[RAG])
        RETURN _Result
1 REPLY 1
HotChilli
Super User
Super User

Sample data and please show the desired result please.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.