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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
VazhaPBI
Frequent Visitor

Allocate Monthly Cost Proportionally to Monthly Product Sales Amount considering customer And catego

Hello Friends,

need help in allocating monthly costs by customer and product category, to monthly sales by customer, product category and product, proportionally to sales amount of month, I have two tables one for sales, second for costs:

Sales Table:

VazhaPBI_2-1682682999938.png


Costs Table:

VazhaPBI_3-1682683024658.png

also i have result column in table showing how it has to be distributed.

Thanks a lot !



2 ACCEPTED SOLUTIONS
MohammadLoran25
Super User
Super User

Hi @VazhaPBI ,

 

1-

TotalSalesPerContext =
CALCULATE (
    SUM ( 'Sales Table'[Sales Amount] ),
    FILTER (
        ALL ( 'Sales Table' ),
        'Sales Table'[Customer] = SELECTEDVALUE ( 'Sales Table'[Customer] )
            && 'Sales Table'[Product Category]
                = SELECTEDVALUE ( 'Sales Table'[Product Category] )
            && 'Sales Table'[Month] = SELECTEDVALUE ( 'Sales Table'[Month] )
    )
)

 

2-

TotalCostPerContext =
CALCULATE (
    SUM ( 'Costs Table'[Cost] ),
    FILTER (
        ALL ( 'Costs Table' ),
        'Costs Table'[Customer] = SELECTEDVALUE ( 'Sales Table'[Customer] )
            && 'Costs Table'[Product Category]
                = SELECTEDVALUE ( 'Sales Table'[Product Category] )
            && 'Costs Table'[Month] = SELECTEDVALUE ( 'Sales Table'[Month] )
    )
)

 

3-

AllocatedCost =
[TotalCostPerContext]
    * DIVIDE ( SUM ( 'Sales Table'[Sales Amount] ), [TotalSalesPerContext] )

 

It helped? Mark it as an accepted solution.
Regards,
Loran

View solution in original post

BiNavPete
Resolver III
Resolver III

Hi
I would manage this in the Power Query Piece


Take a copy of the sales table by referencing the sales table - call it table A
Then merge with costs table on Month Customer and Product Category, selecting costs.
This will put total costs correctly onto each row.

With another reference of the Sales table, prep a table grouping Month,Customer and Product category, sum on Sales. Call it Table B.

Go back to table A and merge with table B to bring in Total sales.

Then simple add column Total Cost/Total Sales * Sales and boom.

 

Sample PBIX here.

Cheers

Pete

View solution in original post

4 REPLIES 4
BiNavPete
Resolver III
Resolver III

Hi
I would manage this in the Power Query Piece


Take a copy of the sales table by referencing the sales table - call it table A
Then merge with costs table on Month Customer and Product Category, selecting costs.
This will put total costs correctly onto each row.

With another reference of the Sales table, prep a table grouping Month,Customer and Product category, sum on Sales. Call it Table B.

Go back to table A and merge with table B to bring in Total sales.

Then simple add column Total Cost/Total Sales * Sales and boom.

 

Sample PBIX here.

Cheers

Pete

Thank You Pete It helped 100%

MohammadLoran25
Super User
Super User

Hi @VazhaPBI ,

 

1-

TotalSalesPerContext =
CALCULATE (
    SUM ( 'Sales Table'[Sales Amount] ),
    FILTER (
        ALL ( 'Sales Table' ),
        'Sales Table'[Customer] = SELECTEDVALUE ( 'Sales Table'[Customer] )
            && 'Sales Table'[Product Category]
                = SELECTEDVALUE ( 'Sales Table'[Product Category] )
            && 'Sales Table'[Month] = SELECTEDVALUE ( 'Sales Table'[Month] )
    )
)

 

2-

TotalCostPerContext =
CALCULATE (
    SUM ( 'Costs Table'[Cost] ),
    FILTER (
        ALL ( 'Costs Table' ),
        'Costs Table'[Customer] = SELECTEDVALUE ( 'Sales Table'[Customer] )
            && 'Costs Table'[Product Category]
                = SELECTEDVALUE ( 'Sales Table'[Product Category] )
            && 'Costs Table'[Month] = SELECTEDVALUE ( 'Sales Table'[Month] )
    )
)

 

3-

AllocatedCost =
[TotalCostPerContext]
    * DIVIDE ( SUM ( 'Sales Table'[Sales Amount] ), [TotalSalesPerContext] )

 

It helped? Mark it as an accepted solution.
Regards,
Loran

Thank you it was also helpful it worked i made slight change.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.