Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Hello everyone! Could you please give some advice on the following issue?
I have two unrelated tables in my model. The first one contains cost by account level throught several years. The second one is at a lower level and contains the sales of products through those accounts over the same time period. I am trying to allocate the cost summarized in the first table to each of the products in the lower level detail table as follows:
1. I've calculated a product share of business in the product sales table, which is the weight of the product sales within an account for the filtered period using the below formula.
Formula:
Solved! Go to Solution.
@Anonymous
I modified the column that I created to consider product sales as the weight.
Product Cost Allocated =
VAR __Filters =
FILTER(
'Account Cost Table',
'Account Cost Table'[Fiscal Year] = 'Product Sales Table'[Fiscal Year] &&
'Account Cost Table'[Quarter] = 'Product Sales Table'[Quarter] &&
'Account Cost Table'[Business Unit] = 'Product Sales Table'[Business Unit] &&
'Account Cost Table'[Account] = 'Product Sales Table'[Account]
)
VAR __TotalSales =
CALCULATE(
SUM('Product Sales Table'[Sales]) ,
ALLEXCEPT( 'Product Sales Table' , 'Product Sales Table'[Fiscal Year] , 'Product Sales Table'[Quarter] , 'Product Sales Table'[Business Unit] ,'Product Sales Table'[Account])
)
VAR __Ratio = DIVIDE( 'Product Sales Table'[Sales] , __TotalSales )
VAR __Result =
CALCULATE(
SUM('Account Cost Table'[Cost]) ,
__Filters
) * __Ratio
RETURN
__Result
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
Link to the dummy files: https://drive.google.com/drive/folders/1CX4SQW_H33zdihYhKS1Hb_PJWg3NkS-s?usp=sharing
@Anonymous
You can save your dummy PBI file in OneDrive, Google Drive, or any other cloud-sharing platform and share the link here. Ensure permission is granted.
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
Thank you! I am posting the link here: https://drive.google.com/drive/folders/1CX4SQW_H33zdihYhKS1Hb_PJWg3NkS-s?usp=sharing
@Anonymous
I added a new column in the Sales table where the allocation of cost is calculated. I then used a measure to sum it.
Product Cost Allocated =
VAR __Filters =
FILTER(
'Account Cost Table',
'Account Cost Table'[Fiscal Year] = 'Product Sales Table'[Fiscal Year] &&
'Account Cost Table'[Quarter] = 'Product Sales Table'[Quarter] &&
'Account Cost Table'[Business Unit] = 'Product Sales Table'[Business Unit] &&
'Account Cost Table'[Account] = 'Product Sales Table'[Account]
)
VAR __RecCount =
CALCULATE(
COUNTROWS('Product Sales Table') ,
REMOVEFILTERS('Product Sales Table'[Product])
)
VAR __Result =
DIVIDE(
CALCULATE(
SUM('Account Cost Table'[Cost]) ,
__Filters
),
__RecCount
)
RETURN
__Result
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
Thanks for looking into it! I think it is a good step forward, however I've tested it with different data and noticed that using the count function to establish the number of product and then using that as a denominator is basically attributing an equal weight to the products that were sold. Therefore, If I change the sales of some products their share of business will stay the same which I want to avoid. Finally, the allocation of cost to each product should be determined by the weight of the product calculated based on the Sales column. I've used part of your code, but I don't have an optimal solution yet.
I've removed the "RecCount" variable and am simply calculating a column with the product cost. Thanks for the tip with the filter context, this is a feature I haven't become familiar with in my couple of weeks experience with DAX and PBI. Next, I use this column to transfer it in a measure. Finally, I create a new column, "Product Cost Alloc_New" where I simply multiply the "Product share of business" with the aforementioned measure of product cost. You can see from the below snapshot that despite the formula allocating each cost correctly according to the share of business, the total is inccorect. Probably because the SUMX context is repeating the product operation "[Product Share of Biz]*[PC as Msr]" also on the total line. Do you have any ideas how to fix this? I've refreshed the files on the google drive with these changes.
Link: https://drive.google.com/drive/folders/1CX4SQW_H33zdihYhKS1Hb_PJWg3NkS-s?usp=sharing
The slightly changed column based on your code:
Snapshot of table with initial cost allocation and the new cost allocation:
@Anonymous
I modified the column that I created to consider product sales as the weight.
Product Cost Allocated =
VAR __Filters =
FILTER(
'Account Cost Table',
'Account Cost Table'[Fiscal Year] = 'Product Sales Table'[Fiscal Year] &&
'Account Cost Table'[Quarter] = 'Product Sales Table'[Quarter] &&
'Account Cost Table'[Business Unit] = 'Product Sales Table'[Business Unit] &&
'Account Cost Table'[Account] = 'Product Sales Table'[Account]
)
VAR __TotalSales =
CALCULATE(
SUM('Product Sales Table'[Sales]) ,
ALLEXCEPT( 'Product Sales Table' , 'Product Sales Table'[Fiscal Year] , 'Product Sales Table'[Quarter] , 'Product Sales Table'[Business Unit] ,'Product Sales Table'[Account])
)
VAR __Ratio = DIVIDE( 'Product Sales Table'[Sales] , __TotalSales )
VAR __Result =
CALCULATE(
SUM('Account Cost Table'[Cost]) ,
__Filters
) * __Ratio
RETURN
__Result
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
Awesome! Thanks a lot!
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 8 | |
| 8 | |
| 3 | |
| 2 | |
| 2 |
| User | Count |
|---|---|
| 23 | |
| 13 | |
| 10 | |
| 6 | |
| 5 |