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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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]
        )
    )

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.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

4 REPLIES 4
v-jianpeng-msft
Community Support
Community Support

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.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.