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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
geirselvag
Frequent Visitor

DAX help - distributed sum

Hello folks,

 

The DAX requirements I'm faced with is include to be able to distribute project cost (or settlement) to other project based on precentage. The basis for DAX is two tables one dim_WBS dimension table, and one fact_Cost transactions table were relationship one-to-many by a WBS id. 

 

Tables:

dim_WBS

geirselvag_0-1733928076676.png

 

fact_COST

geirselvag_1-1733928124972.png

This table include column which is from Excel calculated column, and the number should be calculated by DAX.

 

Current DAX:

geirselvag_2-1733928229511.png

 

I have tried other DAX but gives wrong result. Let me know where am wrong on this code.
Professional DAX people, your help is highly appreciated.

Best regards,

gselvag

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @geirselvag 

 

Sorry for the late reply.

Try to update the measure with the following DAX:

Cost_Distributed_Measure = 
SUMX(
    fact_COST,
    VAR CurrentWBS = fact_COST[WBS]
    VAR CurrentCOST = fact_COST[Cost]
    VAR NewWBS = IF(
        ISBLANK(LOOKUPVALUE(dim_WBS[Settlement_WBS], dim_WBS[WBS], CurrentWBS)),
        CurrentWBS,
        LOOKUPVALUE(dim_WBS[Settlement_WBS], dim_WBS[WBS], CurrentWBS)
    )
    VAR OriginalCost = CALCULATE(
        SUM(fact_COST[Cost]),
        fact_COST[WBS] = NewWBS,
        REMOVEFILTERS(fact_COST)
    )
    VAR Distributed = OriginalCost * LOOKUPVALUE(dim_WBS[Percent], dim_WBS[WBS], CurrentWBS)
    RETURN
    IF(ISBLANK(Distributed), 0, Distributed + CurrentCOST)
)

vxianjtanmsft_0-1735116356784.png

 

Best Regards,
Jarvis Tang
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

This is excellent work.
Thank you!

Kind regards,
Geir

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Hi @geirselvag 

 

You can create a calculated column in fact_COST table with the following DAX:

Cost_Distributed = 
VAR NewWBS = IF(RELATED(dim_WBS[Settlement_WBS]) = BLANK(), fact_COST[WBS], RELATED(dim_WBS[Settlement_WBS]))
VAR OriginalCost = LOOKUPVALUE(fact_COST[Cost], fact_COST[WBS], NewWBS)
VAR Distributed = OriginalCost * RELATED(dim_WBS[Percent])
RETURN
IF(fact_COST[WBS] = NewWBS, 0, fact_COST[Cost] + Distributed)

vxianjtanmsft_0-1733971266530.png

 

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

 

Thanks, but calculated column is not what am looking for. The solution to my issue should be solved as a DAX measure. 


Best regards,
Geir

Anonymous
Not applicable

Hi @geirselvag 

 

Please try to create the following measure:

Cost_Distributed_Measure = 
VAR CurrentWBS = SELECTEDVALUE(fact_COST[WBS])
VAR CurrentCOST = SELECTEDVALUE(fact_COST[Cost])
VAR NewWBS = IF(
    ISBLANK(LOOKUPVALUE(dim_WBS[Settlement_WBS], dim_WBS[WBS], CurrentWBS)),
    CurrentWBS,
    LOOKUPVALUE(dim_WBS[Settlement_WBS], dim_WBS[WBS], CurrentWBS)
)
VAR OriginalCost = CALCULATE(
    SUM(fact_COST[Cost]),
    fact_COST[WBS] = NewWBS,
    REMOVEFILTERS(fact_COST)
)
VAR Distributed = OriginalCost * LOOKUPVALUE(dim_WBS[Percent], dim_WBS[WBS], CurrentWBS)
RETURN
IF(ISBLANK(Distributed), 0, Distributed + CurrentCOST)

 

vxianjtanmsft_0-1734659548397.png

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

Thanks Jarvis, the measure works fine with one row level. I need this to work with subtotal, as there will be between 1-5 levels in the structure. However the measure works perfect on rowlevel only thing missing is the subtotal and grantotal marked in red.

geirselvag_0-1734677839305.png

 

 

Anonymous
Not applicable

Hi @geirselvag 

 

Sorry for the late reply.

Try to update the measure with the following DAX:

Cost_Distributed_Measure = 
SUMX(
    fact_COST,
    VAR CurrentWBS = fact_COST[WBS]
    VAR CurrentCOST = fact_COST[Cost]
    VAR NewWBS = IF(
        ISBLANK(LOOKUPVALUE(dim_WBS[Settlement_WBS], dim_WBS[WBS], CurrentWBS)),
        CurrentWBS,
        LOOKUPVALUE(dim_WBS[Settlement_WBS], dim_WBS[WBS], CurrentWBS)
    )
    VAR OriginalCost = CALCULATE(
        SUM(fact_COST[Cost]),
        fact_COST[WBS] = NewWBS,
        REMOVEFILTERS(fact_COST)
    )
    VAR Distributed = OriginalCost * LOOKUPVALUE(dim_WBS[Percent], dim_WBS[WBS], CurrentWBS)
    RETURN
    IF(ISBLANK(Distributed), 0, Distributed + CurrentCOST)
)

vxianjtanmsft_0-1735116356784.png

 

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

This is excellent work.
Thank you!

Kind regards,
Geir

johnt75
Super User
Super User

You can use RELATED to get the value of column on the one-side of a relationship when you have a row context on the many-side.

Distributed cost =
SUMX ( fact_Cost, fact_Cost[Cost] * ( 1 + RELATED ( dim_wbs[Percent] ) ) )

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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