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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Nic_2022
New Member

Create new column with calculated price per category

Hi,

 

I have a table of different materials which may or may not have a price change. I need to have a price for every month, but at present I only have a price and date when the price has changed, please see data below. I want to add a calculated column to this table which fills in the blanks with the latest Price for each Material according to the Date of Price Change. In the data below I have added what I want to see as the end column: ‘Latest Price’.  I have looked at lots of posts using Lastnonblank and earlier but these are not grouped by Category (i.e. Material in my case) and I can’t return what I’m looking for. Any help is much appreciated.

 

The first 4 columns is what I have in my table and the last column is what I’m trying to achieve.

MaterialStart MonthPrice ChangeDate of Price ChangeLatest Price
NZ.984Jan-214.9627/05/2020 0:004.96
NZ.984Feb-21  4.96
NZ.984Mar-21  4.96
NZ.984Apr-21  4.96
NZ.984May-21  4.96
NZ.984Jun-21  4.96
NZ.984Jul-214.921/07/2021 0:004.92
NZ.984Aug-21  4.92
NZ.984Sep-21  4.92
NZ.984Oct-21  4.92
NZ.984Nov-21  4.92
NZ.984Dec-215.071/12/2021 0:005.07
NZ.984Jan-22  5.07
NZ.984Feb-22  5.07
NZ.984Mar-22  5.07
NZ.433Jan-211.8727/05/2020 0:001.87
NZ.433Feb-21  1.87
NZ.433Mar-211.771/03/2021 0:001.77
NZ.433Apr-211.771/04/2021 0:001.77
NZ.433May-21  1.77
NZ.433Jun-211.771/06/2021 0:001.77
NZ.433Jul-21  1.77
NZ.433Aug-21  1.77
NZ.433Sep-21  1.77
NZ.433Oct-21  1.77
NZ.433Nov-211.771/11/2021 0:001.77
NZ.433Dec-21  1.77
NZ.433Jan-22  1.77
NZ.433Feb-22  1.77
NZ.433Mar-22  1.77
1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

I assume your sample data model has the column type like the attached file.

 

Untitled.png

 

The latest price CC =
VAR _currentstartmonth = Data[Start Month]
VAR _currentmaterial = Data[Material]
VAR _pricetable =
    FILTER (
        SUMMARIZE (
            Data,
            Data[Material],
            Data[Price Change],
            Data[Date of Price Change]
        ),
        Data[Material] = _currentmaterial
            && Data[Date of Price Change] <= _currentstartmonth
    )
VAR _pricetablelatestdate =
    MAXX ( _pricetable, Data[Date of Price Change] )
VAR _latestprice =
    SUMMARIZE (
        FILTER ( _pricetable, Data[Date of Price Change] = _pricetablelatestdate ),
        Data[Price Change]
    )
RETURN
    _latestprice

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

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

2 REPLIES 2
Nic_2022
New Member

Thank you so Much! 😀

Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

I assume your sample data model has the column type like the attached file.

 

Untitled.png

 

The latest price CC =
VAR _currentstartmonth = Data[Start Month]
VAR _currentmaterial = Data[Material]
VAR _pricetable =
    FILTER (
        SUMMARIZE (
            Data,
            Data[Material],
            Data[Price Change],
            Data[Date of Price Change]
        ),
        Data[Material] = _currentmaterial
            && Data[Date of Price Change] <= _currentstartmonth
    )
VAR _pricetablelatestdate =
    MAXX ( _pricetable, Data[Date of Price Change] )
VAR _latestprice =
    SUMMARIZE (
        FILTER ( _pricetable, Data[Date of Price Change] = _pricetablelatestdate ),
        Data[Price Change]
    )
RETURN
    _latestprice

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

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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