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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

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£90
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 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
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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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