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
Anonymous
Not applicable

Raw Material Price

Hi guys, 

I have a measure (amount) whose define my amount of raw material and a table with this columns

-raw material

-price

-amount

-date of purchase

 

What I need is another measure to define my price. For example, if my measure amount is 5000 for material 1 and my table is like:

 

raw materialpriceamountdate of purchase
material12,9200018/dec/2023
material11,8350020/dec/2023
material23,4100012/dec/2023
material20,8150010/oct/2023

 

I need to order my table by date of purchase descendent and calculate something like this:

 

3500*1,8 + (1500)*2,9 = 10650

 

Important, my amount is 5000, so I cant to surpass this amount, that's why I used 1500 instead of 2000 to multiply by 2,9.

 

How can I do this measure?

1 ACCEPTED SOLUTION
Sahir_Maharaj
Super User
Super User

Hello @Anonymous,

 

Can you please try this:

 

 

Calculate Price = 
VAR TotalAmountNeeded = 5000
VAR CumulativeTable = 
    ADDCOLUMNS(
        FILTER(
            'YourTable',
            'YourTable'[raw material] = "material1"
        ),
        "CumulativeAmount", 
        CALCULATE(
            SUM('YourTable'[amount]), 
            FILTER(
                ALL('YourTable'),
                'YourTable'[date of purchase] <= EARLIER('YourTable'[date of purchase]) &&
                'YourTable'[raw material] = EARLIER('YourTable'[raw material])
            )
        )
    )
VAR Result = 
    SUMX(
        CumulativeTable,
        IF(
            [CumulativeAmount] <= TotalAmountNeeded,
            [amount] * [price],
            MAX(0, TotalAmountNeeded - [CumulativeAmount] + [amount]) * [price]
        )
    )
RETURN 
    Result

 


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ About: https://sahirmaharaj.com/about.html
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

View solution in original post

2 REPLIES 2
Sahir_Maharaj
Super User
Super User

Hello @Anonymous,

 

Can you please try this:

 

 

Calculate Price = 
VAR TotalAmountNeeded = 5000
VAR CumulativeTable = 
    ADDCOLUMNS(
        FILTER(
            'YourTable',
            'YourTable'[raw material] = "material1"
        ),
        "CumulativeAmount", 
        CALCULATE(
            SUM('YourTable'[amount]), 
            FILTER(
                ALL('YourTable'),
                'YourTable'[date of purchase] <= EARLIER('YourTable'[date of purchase]) &&
                'YourTable'[raw material] = EARLIER('YourTable'[raw material])
            )
        )
    )
VAR Result = 
    SUMX(
        CumulativeTable,
        IF(
            [CumulativeAmount] <= TotalAmountNeeded,
            [amount] * [price],
            MAX(0, TotalAmountNeeded - [CumulativeAmount] + [amount]) * [price]
        )
    )
RETURN 
    Result

 


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ About: https://sahirmaharaj.com/about.html
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning
Anonymous
Not applicable

Thank you very much, @Sahir_Maharaj!

It is just what I needed, I just made some little changes, but the main logic is what you did!


Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.