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

Get Fabric certified for FREE! Don't miss your chance! Learn more

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]
        )
    )

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.


Click here to visit my LinkedIn page

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]
        )
    )

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.


Click here to visit my LinkedIn page

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
Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.