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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
dw700d
Post Patron
Post Patron

Allocating Cost Formula

Good day

The table below shows a project # and in certain cases multiple locations per project. The cost for each project is charged to "Central" Location as shown in the example below. I would like to create a formula that evenly allocates the cost charged at the central location to the states within each project. For example in project C 150k will be evenly allocated to MA & KY.  Can anyone help?

 

Project#            LocationCost
ACentral  200,000.00
ANY0
BCentral  300,000.00
BLA0
CCentral  300,000.00
CMA0
CKY0
DCentral  150,000.00
ECentral    10,000.00
EWY0
EIL0
ECA0
2 ACCEPTED SOLUTIONS
ryan_mayu
Super User
Super User

@dw700d 

is this waht you want?

Column = if('Table'[Location]="Central",'Table'[Cost],maxx(FILTER('Table','Table'[Project#            ]=EARLIER('Table'[Project#            ])&&'Table'[Location]="Central"),'Table'[Cost]/CALCULATE(COUNTROWS('Table'),'Table'[Location]<>"Central",ALLEXCEPT('Table','Table'[Project#            ]))))

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

Icey
Community Support
Community Support

Hi @dw700d ,

 

What @ryan_mayu  created is a custom column using M language in Power Query Editor.

If you wnat to create a column or measure using DAX, try this:

Column =
VAR Cost_ =
    CALCULATE ( SUM ( 'Table'[Cost] ), ALLEXCEPT ( 'Table', 'Table'[Project#] ) )
VAR LocationCount =
    CALCULATE (
        COUNT ( 'Table'[Location] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Project#] ),
            'Table'[Location] <> "Central"
        )
    )
RETURN
    IF ( 'Table'[Location] = "Central", [Cost], DIVIDE ( Cost_, LocationCount ) )

Column.PNG

 

Measure =
VAR Cost_ =
    CALCULATE ( SUM ( 'Table'[Cost] ), ALLEXCEPT ( 'Table', 'Table'[Project#] ) )
VAR LocationCount =
    CALCULATE (
        COUNT ( 'Table'[Location] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Project#] ),
            'Table'[Location] <> "Central"
        )
    )
RETURN
    IF ( MAX( 'Table'[Location] ) = "Central", Cost_, DIVIDE ( Cost_, LocationCount ) )

Measure.PNG

 

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
Jihwan_Kim
Super User
Super User

Hi, @dw700d 

 

Please try the below DAX measure.

 

Cost evenly allocate =
IF (
CALCULATE (
COUNT ( 'Table'[Project#] ),
ALLEXCEPT ( 'Table', 'Table'[Project#] )
) > 1,
IF (
SELECTEDVALUE ( 'Table'[Location] ) = "Central",
BLANK (),
DIVIDE (
CALCULATE ( SUM ( 'Table'[Cost] ), ALLEXCEPT ( 'Table', 'Table'[Project#] ) ),
CALCULATE (
COUNT ( 'Table'[Project#] ),
ALLEXCEPT ( 'Table', 'Table'[Project#] )
) - 1
)
),
CALCULATE ( SUM ( 'Table'[Cost] ), ALLEXCEPT ( 'Table', 'Table'[Project#] ) )
)

 

Hi, My name is Jihwan Kim.

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

@Jihwan_Kim 

Thank you for the repsonse. The numbers are not allocating correctly. Any other suggestions?

 

dw700d_0-1617637107205.png

 

Hi,

If it is OK with you, can I see your sample pbix file that you used the measure for the above?


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
ryan_mayu
Super User
Super User

@dw700d 

is this waht you want?

Column = if('Table'[Location]="Central",'Table'[Cost],maxx(FILTER('Table','Table'[Project#            ]=EARLIER('Table'[Project#            ])&&'Table'[Location]="Central"),'Table'[Cost]/CALCULATE(COUNTROWS('Table'),'Table'[Location]<>"Central",ALLEXCEPT('Table','Table'[Project#            ]))))

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




@ryan_mayu 

Thanks Ryan I cant get past the if statement. It doesnt recognize my table or columns. Could there be something missing from the measure?

dw700d_1-1617637677874.png

 

Icey
Community Support
Community Support

Hi @dw700d ,

 

What @ryan_mayu  created is a custom column using M language in Power Query Editor.

If you wnat to create a column or measure using DAX, try this:

Column =
VAR Cost_ =
    CALCULATE ( SUM ( 'Table'[Cost] ), ALLEXCEPT ( 'Table', 'Table'[Project#] ) )
VAR LocationCount =
    CALCULATE (
        COUNT ( 'Table'[Location] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Project#] ),
            'Table'[Location] <> "Central"
        )
    )
RETURN
    IF ( 'Table'[Location] = "Central", [Cost], DIVIDE ( Cost_, LocationCount ) )

Column.PNG

 

Measure =
VAR Cost_ =
    CALCULATE ( SUM ( 'Table'[Cost] ), ALLEXCEPT ( 'Table', 'Table'[Project#] ) )
VAR LocationCount =
    CALCULATE (
        COUNT ( 'Table'[Location] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Project#] ),
            'Table'[Location] <> "Central"
        )
    )
RETURN
    IF ( MAX( 'Table'[Location] ) = "Central", Cost_, DIVIDE ( Cost_, LocationCount ) )

Measure.PNG

 

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@dw700d 

are you creating a measure or a column? my solution is for a new column, not a measure. You want a solution for a measure?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.