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

See when key Fabric features will launch and what’s already live, all in one place and always up to date. Explore the new Fabric roadmap

Reply
nicoenz
Helper III
Helper III

sum from multiple tables

Hi everyone,

I really need help on building an expression that i can't get it to work properly.

i have the following star schema (coloured fields are the connected ones).
The two unrelated tables (Dim_Proc_forecast_versions...) are there to calculate the same expression twice.

nicoenz_0-1730375601713.png

I want to compare two versions to determine the impact on each component for the selected "Material_Code" (one or more from the slicer on Dim_PH123). I need to obtain the final volume from the "SourceData" table, the amount per component from the "Exploded BOM" table, and the price from the "Procurement Forecast" table.

The expression should compute: Final volume * Amount * Price difference.


The formula I wrote works perfectly well on each component but the total is not OK. I am frying my brain but nothing I change works. Can you please help me?

"

Price Impact RM =
VAR SelectedVersion1 = SELECTEDVALUE(Dim_Procurement_forecast_versions_RM1[Version])
VAR SelectedVersion2 = SELECTEDVALUE(Dim_Procurement_forecast_versions_RM2[Version])
 
RETURN
SUMX(
    VALUES(Dim_PH123[Material_Code]),
    VAR FinalVolumeKG = CALCULATE(SUM(SourceData[Final_Volume_KG]))
    VAR Quantity = CALCULATE(SUM('Exploded BOM'[Amount]))
    VAR Price1 = CALCULATE(
        SUMX('Procurement forecast', 'Procurement forecast'[Price]),
        FILTER(
            ALL('Procurement forecast'[PriceType]),
            'Procurement forecast'[PriceType] = SelectedVersion1
        ),
        FILTER(
            ALL('Procurement forecast'[Version]),
            'Procurement forecast'[Version] = SelectedVersion1
        )
    )
    VAR Price2 = CALCULATE(
        SUMX('Procurement forecast', 'Procurement forecast'[Price]),
        FILTER(
            ALL('Procurement forecast'[PriceType]),
            'Procurement forecast'[PriceType] = SelectedVersion2
        ),
        FILTER(
            ALL('Procurement forecast'[Version]),
            'Procurement forecast'[Version] = SelectedVersion2
        )
    )

    RETURN
    FinalVolumeKG * Quantity * (Price1 - Price2)
)
"

See example below:
Volume for "Material 1" is 503 kg and for "Material 2" is 15 kg
The table i get is:

nicoenz_1-1730377660946.png

(the volumes are not right there)

Thanks for your help!!!!!!!

2 REPLIES 2
nicoenz
Helper III
Helper III

Hi @rajendraongole1 ,

thanks for your help!!!!. it doesn't work well. I created a simplified version of the file. I'd really appreciate it if you can take a look into it:
https://drive.google.com/file/d/1sqs3HbmrcoTz4pyNVYd5WyG0bLOp-ynt/view?usp=sharing 

Thanks!

nico

rajendraongole1
Super User
Super User

Hi @nicoenz - Adjusting the calculation to ensure the aggregation respects the total context.

Price Impact RM =
VAR SelectedVersion1 = SELECTEDVALUE(Dim_Procurement_forecast_versions_RM1[Version])
VAR SelectedVersion2 = SELECTEDVALUE(Dim_Procurement_forecast_versions_RM2[Version])

VAR FinalVolumeKG = CALCULATE(SUM(SourceData[Final_Volume_KG]))
VAR AmountPerComponent = CALCULATE(SUM('Exploded BOM'[Amount]))

VAR PriceDifference =
CALCULATE(
SUMX(
'Procurement forecast',
VAR Price1 = CALCULATE(
SUM('Procurement forecast'[Price]),
FILTER(
ALL('Procurement forecast'[PriceType]),
'Procurement forecast'[PriceType] = SelectedVersion1
),
FILTER(
ALL('Procurement forecast'[Version]),
'Procurement forecast'[Version] = SelectedVersion1
)
)
VAR Price2 = CALCULATE(
SUM('Procurement forecast'[Price]),
FILTER(
ALL('Procurement forecast'[PriceType]),
'Procurement forecast'[PriceType] = SelectedVersion2
),
FILTER(
ALL('Procurement forecast'[Version]),
'Procurement forecast'[Version] = SelectedVersion2
)
)
RETURN Price1 - Price2
)
)

RETURN
SUMX(
VALUES(Dim_PH123[Material_Code]),
FinalVolumeKG * AmountPerComponent * PriceDifference
)

 

This structure should maintain correct values for each component row and the grand total.

 

Hope this helps , and let me know if any 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
May PBI 25 Carousel

Power BI Monthly Update - May 2025

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

May 2025 Monthly Update

Fabric Community Update - May 2025

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