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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
NorbertG
Helper I
Helper I

How to use changed price for sales which happen after price update date?

Hi everyone.
I have three tables. 1st one 'price', 2nd one 'product', 3rd is 'sales' 

price_idid_refdateactiveprice
141301.01.2023TRUE10
241401.01.2023TRUE11
344401.01.2023FALSE12
444401.09.2023TRUE11,4

 

product_idid_refname
11412frame
12413door
13414window
14444chair

 

sale_idproduct_idquantitydate_of_saleprice*quantity
21121020.01.2023 
22131015.03.2023 
23141030.06.2023 
24141011.09.2023 

Relationships:
'price'[id_ref] *:1 'product'[id_ref]
'product'[product_id] *:1 'sales'[product_id]

All i want to achieve is for the column 'sales'[quantity*price] to take approperiate value from table price, according to 'sales'[date_of_sale]

1 ACCEPTED SOLUTION
ERD
Community Champion
Community Champion

Your column:

Column =
VAR _pr_id = sales[product_id]
VAR _id_ref =
    RELATED ( 'product'[id_ref] )
VAR _dt = sales[date_of_sale]
VAR _max_dt =
    CALCULATE (
        MAX ( 'price'[date] ),
        'price'[id_ref] = _id_ref,
        'price'[date] <= _dt
    )
RETURN
    CALCULATE (
        MAX ( 'price'[price] ),
        'price'[id_ref] = _id_ref,
        'price'[date] = _max_dt
    ) * sales[quantity]

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

View solution in original post

6 REPLIES 6
ERD
Community Champion
Community Champion

Hi @NorbertG , the calculated colmn:

Column =
VAR _id = sales[id]
VAR _item = sales[item_id]
VAR _dt = sales[date_of_sale]
VAR _max_dt =
    CALCULATE (
        MAX ( 'product'[date] ),
        'product'[id] = _id,
        'product'[id_ref] = _item,
        'product'[date] <= _dt
    )
RETURN
    CALCULATE (
        MAX ( 'product'[price] ),
        'product'[id] = _id,
        'product'[id_ref] = _item,
        'product'[date] = _max_dt
    ) * sales[quantity]

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Sadly, it doesn't work for me. It is all on me because i made mistake in my explanation. I forgot about table in between them.

ERD
Community Champion
Community Champion

@NorbertG , please, check again your data. What's in your sales table? Column name is product_id, but data is id_ref.

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

I checked my data. Really sorry for the inconvinience

ERD
Community Champion
Community Champion

Your column:

Column =
VAR _pr_id = sales[product_id]
VAR _id_ref =
    RELATED ( 'product'[id_ref] )
VAR _dt = sales[date_of_sale]
VAR _max_dt =
    CALCULATE (
        MAX ( 'price'[date] ),
        'price'[id_ref] = _id_ref,
        'price'[date] <= _dt
    )
RETURN
    CALCULATE (
        MAX ( 'price'[price] ),
        'price'[id_ref] = _id_ref,
        'price'[date] = _max_dt
    ) * sales[quantity]

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Thank you! Now it works as it should. I'm really sorry for my mistakes and again I'm really thankful!

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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