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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Morasm
Frequent Visitor

Budget sums across all entries when using a calculated column

Hi.

 

I have a problem which I am even having a bit of a hard time explaining.


I have provided the following minimal example with some dummy data.


We have some old sales data in a sales table. It used to be that each sale had a “LegacyCostCenterName” attached to it, but as that proved to inflexible, we have instead added a new column called “OperationsId”. Then we have a table mapping operations IDs to a CostCenterID which references a CostCenter details table. (This makes more sense in my data where it is not sales we work with, but that context is a bit complex explaining here).


Each CostCenterID also has a budget in a budget table.


Since not all operations IDs in the sales table have yet been mapped to a CostCenterID, I have introduced a new column called EffectiveCostCenter. This will use the name from the CostCenterDetails if it exists, otherwise it will use the LegacyCostCentername of the sale row.

These are my tables and relations

Morasm_2-1713171433159.png

 

 

This is where the problem comes in. If I create a matrix with the EffectiveCostCenter, it is not able to correctly map the Budget, so for each CostCenter it shows the combined budget of all the cost centers.

Morasm_0-1713171270221.png

Notice that all the budgets are the same, even though they should be different for each Cost Center.

If I use the Cost Center name from the CostCenterDetails table, then the budgets are correct, but then I do not get the correct name for the sales which are not yet mapped to a CostCenter and are using the legacy name.
 

Morasm_1-1713171376027.png

 

I suspect that the problem is in the FACT_Sales table where the calculated column "EffectiveCostCenter" means we are traversing a number of many-to-one and one-to-many relations which cannot be properly resolved.

 

DateLegacyCostCenterNameOpertaionsIdAmount

EffectiveCostCenter

1/1/2024Old CC 1A20

Cost Center A

1/1/2024Old CC 1A20Cost Center A
1/1/2024Old CC 1B30Cost Center A
1/1/2024Old CC 1C40Cost Center A
1/1/2024Old CC XX5Old CC X
1/1/2024Old CC 3D100Cost Center B
1/2/2024Old CC 1A10Cost Center A
1/2/2024Old CC 1A20Cost Center A
1/2/2024Old CC 1B30Cost Center A
1/2/2024Old CC 1C70Cost Center A
1/2/2024Old CC XX5Old CC X
1/2/2024Old CC 3D150Cost Center B

 

You can see the whole example here: minimal example.pbix

 

I can change most of the tables and relations, except the Sales table which I can only add new columns to

4 REPLIES 4
Anonymous
Not applicable

Hi @Morasm 


This issue is caused by the relationship between the sales table and budget table:

vzhengdxumsft_0-1713234641094.png

Maybe you can try the crossjoin() function:

Create a new table with dax:

Table =
FILTER (
    CROSSJOIN (
        FILTER (
            GENERATE (
                SELECTCOLUMNS (
                    'Budget',
                    'Budget'[Budget],
                    'Budget'[CostCenterID],
                    'Budget'[Date]
                ),
                SELECTCOLUMNS (
                    'DIM_CostCenterDetails',
                    'DIM_CostCenterDetails'[CostCenterID],
                    'DIM_CostCenterDetails'[CostCenterName]
                )
            ),
            'Budget'[CostCenterID] = 'DIM_CostCenterDetails'[CostCenterID]
        ),
        'FACT_Sales'
    ),
    'DIM_CostCenterDetails'[CostCenterName] = 'FACT_Sales'[EffectiveCostCenter]
        && 'Budget'[Date] = 'FACT_Sales'[Date]
)

vzhengdxumsft_1-1713235044800.png

Then create a relationship between this table and the DIM_dates table:

vzhengdxumsft_2-1713235104923.png

The result is as follow:

vzhengdxumsft_3-1713235134865.png

Below is the pbix:

 

Best Regards

Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you for the reply Zhengdong Xu

 

The result you showed have summed the budgets on the days. Cost Center A (id: 1) should have a budget of 100 on January 1 and January 2.

But because there was 4 sales on each of thoes two days for Cost Center A (cost center id: 1), the matrix shows a budget of 400.

Morasm
Frequent Visitor

I can fix the summing of budgets by using the Average instead. It feels a bit yucky and I wonder if it becomes a problem down the line. For instance if I also want a graphic visualization.

 

However I also just saw that the matrix is missing the "Old CC X" column for the sale where there is no mapping for the Operations ID

Morasm
Frequent Visitor

The suggestion lead me to creating the following table which seems to work on the small dataset. I'll try to implement it in my real report and see what happens:

Table = 
ADDCOLUMNS(
        SUMMARIZE(
            NATURALLEFTOUTERJOIN(
                FACT_Sales, 
                DIM_CostCenterDetails
            ),
            DIM_CostCenterDetails[CostCenterID], 
            DIM_Dates[Dates], 
            FACT_Sales[EffectiveCostCenter], 
            "Amount", SUM(FACT_Sales[Amount]
            )
        ),
        "Budget", CALCULATE(SUM(FACT_Budget[Budget])   
    )
   
)

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.

Top Solution Authors