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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Calculating SUM where multiple conditions are met between tables without a relationship

I'm working a scrap report for a manufacturing company.

 

I have a table of transactions that show what material was scrapped including when it happened and how much was scrapped.

 

I have a table of materials cost data that details, for each material, how much of the cost is from variable costs, fixed costs, labor costs, etc.

 

Both the transactions table and materials costs table have active relationships to a Calendar table.

 

The cost data changes once a year, and on the same date every year, so I've "concatenated several" tables of costs data (using Get Data > Folder) and this new mega table has "DateValidFrom" and "DateValidTo" columns in it. I added them myself, that's the only way I could think of to deal with the cost data changing periodically; I needed some way to match a transaction with the cost data relevent when the transaction happened.

 

Because of that, materials will appear in my cost table mutiple times. Once with data for 2017, once for 2018, etc. That prevents me from making a relationship between the material number in the transactions table with the material number in the materials costs table, as the material number appears more than once in the materials costs table.

 

What I need to do is sum, for example, the "Fixed Cost" for every transaction for each material number where:

  1. The material numbers matches in the transactions and costs tables.
  2. The transaction happened on or after the "date valid from" in the materials cost table.
  3. The transaction happened on or before the "date valid to" in the materials costs table.

This isn't the hard part, but I then need to multiply the sum of the fixed cost for that material by how many of them were scrapped in that transaction, and then divide that by the lot size for that material. This is because though only 2 of Bolt XYZ may have been scrapped, they are purchased in boxes of 100.

 

I'm having trouble with the DAX on this and have tried a number of combinations using CALCULATE(), RELATED(), USERELATIONSHIP(), etc. It's not even close to working, but since I'm in unfamiliar territory with DAX, I don't even know how to troubleshoot it.

 

Strangely, that ALLEXCEPT() function was the only way I could get it to (previously) sum the fixed costs for a single material number instead of all materials in the table.

 

Cost Fix = CALCULATE(
                        SUM(All_MaterialsCosts[Mfg.Overhead Fix]),
                        ALLEXCEPT(All_MaterialsCosts,All_MaterialsCosts[Material]),
                        AND(
                            All_Transactions[Posting Date] >= USERELATIONSHIP(All_MaterialsCosts[DateValidFrom],'Calendar'[Date]),
                            All_Transactions[Posting Date] <= USERELATIONSHIP(All_Transactions[DateValidTo], 'Calendar'[Date])
                            )
                        )
               * All_Transactions[Quantity]/RELATED(All_MaterialsCosts[Costing Lot Size])

Any suggestions on how to tackle this will be greatly apprecaited. Thanks for your time.

4 REPLIES 4
Anonymous
Not applicable

Here's another attempt:

 

Cost Fix = 
CALCULATE(
    SUM(All_MaterialsCosts[Mfg.Overhead Fix]),
    ALLEXCEPT(All_MaterialsCosts, All_MaterialsCosts[Material]),
    FILTER(All_Transactions, All_Transactions[Posting Date]) >= VALUES(All_MaterialsCosts[DateValidFrom]),
    FILTER(All_Transactions, All_Transactions[Posting Date]) <= VALUES(All_MaterialsCosts[DateValidTo])
    )
Greg_Deckler
Super User
Super User

Can you supply sample/example data, can't wrap my head around what is going here.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Yeah, I want to. It's just going to take me a little while to anonymize it. But, I'll work on it. Thanks for the interest in the meantime!

Hi @Anonymous,

 

Have you worked out your requirement bu yourself? If so, would you please share your solution to benefit more community members?

 

Regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.