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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Jtbonner1986
Helper I
Helper I

Returning the latest value by date, if no value for date period return the previous value

Hello 

 

I have a data set and I have a calendar table. I want to plot the last price paid by calendar month. If there is no data for that month I want the previous months value etc etc. 

 

Example of my Data Set:

 

MaterialDate

Cost

 

 

12301/06/2024£100
12301/05/2024£85
12310/05/2024£95
12301/03/2024£85
12328/03/2024£90
12301/01/2024£50

 

The result i want to see is:

 

MaterialDateLast Price Paid
123Jan-2024£50
123Feb-2024£50
123Mar-2024£90
123Apr-2024£90
123May-2024£95
123Jun-2024

£100

 

Struggling to plot where there are gaps in the dataset on a visual, trying to use the calendar table 

 

please help

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

If you have a maximum of 1 entry per material per date then the below should work I think.

Last Price Paid =
VAR MaxDate =
    MAX ( 'Date'[Date] )
VAR BaseTable =
    CALCULATETABLE (
        SUMMARIZE ( 'Table', 'Table'[Date], 'Table'[Cost] ),
        'Date'[Date] <= MaxDate
    )
VAR Result =
    SELECTCOLUMNS (
        TOPN ( 1, BaseTable, 'Table'[Date], DESC ),
        "@value", 'Table'[Cost]
    )
RETURN
    Result

View solution in original post

1 REPLY 1
johnt75
Super User
Super User

If you have a maximum of 1 entry per material per date then the below should work I think.

Last Price Paid =
VAR MaxDate =
    MAX ( 'Date'[Date] )
VAR BaseTable =
    CALCULATETABLE (
        SUMMARIZE ( 'Table', 'Table'[Date], 'Table'[Cost] ),
        'Date'[Date] <= MaxDate
    )
VAR Result =
    SELECTCOLUMNS (
        TOPN ( 1, BaseTable, 'Table'[Date], DESC ),
        "@value", 'Table'[Cost]
    )
RETURN
    Result

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.

Top Solution Authors