cancel
Showing results for 
Search instead for 
Did you mean: 
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
September Update

Check it Out!

Click here to learn more about the September 2022 updates!

Power BI Show episode 9

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power BI Dev Camp Session 26

New Date - Check it Out!

Mark your calendars and join us on Thursday, October 6 at 11a PDT for a great session with Ted Pattison!

Top Solution Authors