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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
TCavins
Helper V
Helper V

DAX - get most recent value from any previous row based on 2 filters

I have a table similar to the following

 

PERSON IDCALENDAR IDSTATUSRATEMostRecentOpenRate
11VOID3.00 
12OPEN4.50 
13BUSY2.004.50
21OPEN6.50 
22DOWN3.006.50
23BUSY2.006.50
24OPEN5.50 
25BUSY1.755.50
     
     

 

For each row, I want a column to give me the the most recent Rate for the same person where Status = OPEN from an earlier Calendar ID. The table I have is already sorted by person and calendar ID.

 

I've shown the column I want above for MostRecentOpenRate. How can I use DAX to calculate the value for MostRecentOpenRate?

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file whether it suits your requirement.

It is for creating a calculated column.

 

Jihwan_Kim_0-1731961584135.png

 

 

MostRecentOpenRate CC =
VAR _personid = Data[PERSON ID]
VAR _calendarid = Data[CALENDAR ID]
VAR _recentopencalendarid =
    MAXX (
        FILTER (
            Data,
            Data[PERSON ID] = _personid
                && Data[CALENDAR ID] < _calendarid
                && Data[STATUS] = "OPEN"
        ),
        Data[CALENDAR ID]
    )
RETURN
    IF (
        NOT Data[STATUS] = "OPEN",
        MAXX (
            FILTER (
                Data,
                Data[PERSON ID] = _personid
                    && Data[CALENDAR ID] = _recentopencalendarid
            ),
            Data[RATE]
        )
    )

 

    Microsoft MVP
 

 

   


      If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


   


     
        LinkedInVisit my LinkedIn page
     

   


   


     
        Outlook BookingSchedule a short Teams meeting to discuss your question

     

   


 


View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Your solution is so great Jihwan_Kim  and Ashish_Mathur

Hi, @TCavins 

Thank you so much for raising your questions in the community! If Super user's reply solves your doubt, you can mark it as a "solution" so that other friends who encounter similar problems can also find the answer. This will go a long way in helping others in the community. Thank you again for participating!

 

Best Regards

Jianpeng Li

 

Ashish_Mathur
Super User
Super User

Hi,

Use this calculated column formula

Column = if(Data[STATUS]="Open",BLANK(),LOOKUPVALUE(Data[RATE],Data[CALENDAR ID],CALCULATE(MAX(Data[CALENDAR ID]),FILTER(Data,Data[PERSON ID]=EARLIER(Data[PERSON ID])&&Data[CALENDAR ID]<EARLIER(Data[CALENDAR ID])&&Data[STATUS]="Open")),Data[PERSON ID],Data[PERSON ID]))

Ashish_Mathur_0-1731974192074.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file whether it suits your requirement.

It is for creating a calculated column.

 

Jihwan_Kim_0-1731961584135.png

 

 

MostRecentOpenRate CC =
VAR _personid = Data[PERSON ID]
VAR _calendarid = Data[CALENDAR ID]
VAR _recentopencalendarid =
    MAXX (
        FILTER (
            Data,
            Data[PERSON ID] = _personid
                && Data[CALENDAR ID] < _calendarid
                && Data[STATUS] = "OPEN"
        ),
        Data[CALENDAR ID]
    )
RETURN
    IF (
        NOT Data[STATUS] = "OPEN",
        MAXX (
            FILTER (
                Data,
                Data[PERSON ID] = _personid
                    && Data[CALENDAR ID] = _recentopencalendarid
            ),
            Data[RATE]
        )
    )

 

    Microsoft MVP
 

 

   


      If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


   


     
        LinkedInVisit my LinkedIn page
     

   


   


     
        Outlook BookingSchedule a short Teams meeting to discuss your question

     

   


 


Thank you for your response! It's pretty close to where I was going using variables instead of EARLIER, however I was not using MAXX and I think this reads easier that what I was attempting to do.

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.