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
Gekko1
Helper I
Helper I

Get last record prior to selected in slicers

So, I'm currently having an issue as described below:

  • I have this table (let's call it Table X) where I have the company ID, which is related to the companies table by the same field (ID);
  • There is also the product ID, which is related to products table by the ID field too;
  • There is a field which is the amount of the product and the date that amount was "measured"
CompanyProductAmountDate
11515002022-01-01
11620002022-02-01
21520002022-01-15
2163000

2022-02-15

 

With that in mind, I need a measure which gets the product amount on the last date available. Example, if I select the february month on slicers it should show the amount 2000 (since there's no data for february, it gets the last date prior to february) for the product 15 and 3000 for the product 16. 

1 ACCEPTED SOLUTION
ppm1
Solution Sage
Solution Sage

For that, you need a separate Date/Calendar table in your model with a 1:M relationship to the Date column in your table. You can then use a measure like this one to get your result. Replact T3Dates and T3 with your Calendar table and original table, respectively.

ppm1_0-1675691380815.png

Latest =
VAR maxdate =
    MAX ( T3Dates[Date] )
RETURN
    CALCULATE (
        LASTNONBLANKVALUE ( T3[Date], SUM ( T3[Amount] ) ),
        REMOVEFILTERS ( T3Dates ),
        T3Dates[Date] <= maxdate
    )

 

Pat

Microsoft Employee

View solution in original post

1 REPLY 1
ppm1
Solution Sage
Solution Sage

For that, you need a separate Date/Calendar table in your model with a 1:M relationship to the Date column in your table. You can then use a measure like this one to get your result. Replact T3Dates and T3 with your Calendar table and original table, respectively.

ppm1_0-1675691380815.png

Latest =
VAR maxdate =
    MAX ( T3Dates[Date] )
RETURN
    CALCULATE (
        LASTNONBLANKVALUE ( T3[Date], SUM ( T3[Amount] ) ),
        REMOVEFILTERS ( T3Dates ),
        T3Dates[Date] <= maxdate
    )

 

Pat

Microsoft Employee

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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.