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
zubairs
Helper I
Helper I

Cost allocation by branch

Hi Guys,

 

So this is a probelm that I've not been able to resolve for the longest of time.

 

So I have two different data sets, one for revenue and one for cost. The data is calculated by geographic region and follows the hierarchy as such:

 

  • Route (lowest level)
  • Branch
  • Region 
  • Country (highest level)

The costing is done on branch level and now I just need to allocate the cost to each route. I want the DAX to be dynamic in a way, that it should show me the cost of branch when a branch is selected but also allocate the cost to routes when I want to see the route level.

 

In the example you can see that the Branch has 6 routes, so the Logistics SAP and Sales Force SAP cost should be allocated to each route. Whereas, it is currently showing the total of the branch against each route.

 

This is the DAX that I am using:  

Logistics SAP (Cost per route) = DIVIDE(
-[Logistics Cost (KSA)],
DISTINCTCOUNT(Region_to_Van_mapping[Route]),
0)

zubairs_2-1624465782415.png

 

 

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

I think you want to multiply the cost by the fraction of routes in the current context over the total number of routes for that branch.

 

This should get you close:

Logistics SAP (Cost per route) =
- [Logistics Cost (KSA)]
    * DIVIDE (
        DISTINCTCOUNT ( Region_to_Van_mapping[Route] ),
        CALCULATE (
            DISTINCTCOUNT ( Region_to_Van_mapping[Route] ),
            REMOVEFILTERS ( Region_to_Van_mapping[Route] )
        ),
        0
    )

 

In your code, DISTINCTCOUNT is just 1 for each of the routes since the route is part of the filter context for those rows (which is why I remove that filter in the denominator for my DAX).

View solution in original post

2 REPLIES 2
zubairs
Helper I
Helper I

@AlexisOlson thank you so much. I had been killing myself over this for the longest time now. You're a Godsent my friend!

AlexisOlson
Super User
Super User

I think you want to multiply the cost by the fraction of routes in the current context over the total number of routes for that branch.

 

This should get you close:

Logistics SAP (Cost per route) =
- [Logistics Cost (KSA)]
    * DIVIDE (
        DISTINCTCOUNT ( Region_to_Van_mapping[Route] ),
        CALCULATE (
            DISTINCTCOUNT ( Region_to_Van_mapping[Route] ),
            REMOVEFILTERS ( Region_to_Van_mapping[Route] )
        ),
        0
    )

 

In your code, DISTINCTCOUNT is just 1 for each of the routes since the route is part of the filter context for those rows (which is why I remove that filter in the denominator for my DAX).

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!

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.