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
Community Champion
Community Champion

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
Community Champion
Community Champion

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

Helpful resources

Announcements
PBI_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Get Ready for Power BI Dev Camp

Microsoft named a Leader in The Forrester Wave

Microsoft received the highest score of any vendor in both the strategy and current offering categories.

Get Ready for Power BI Dev Camp

Power BI Dev Camp - September 30th, 2021

Mark your calendars and join us for our next Power BI Dev Camp!

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Top Solution Authors