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
turp111
Frequent Visitor

New DAX measure to sum values that exist in prior column

I have a matrix visual with several columns per Plan ID.  I'm trying to add one more DAX measure/column that will sum the values in the Comp Amount column for each Child Component, per Parent Component.  The pic below is kinda oversimplified (and I did it in Excel just for dispay purposes) but it gets the idea across.  The circled column in the pic here is what I'm wanting to add.  You can see that for each Parent Component there are multiple Child Components.  I just need one more column with total PER Parent Component...PER Plan ID.  So there could be more PLan IDs listed here with the same type of look.  Below are some of the expressions I've tried to no avail.  I'm sure I'm just missing something small.  Thanks! 

 

FYI - the POS_NEG_AMOUNTS value in the DAX expression below are the amount values I have in my table (ex: -500, 200.75, -1033.48, etc.).

 

0.03 - COST_OF_COMP_CARD =
VAR COC_TYPE_ID = CALCULATE(
        MAX('Breakdown Table (plancomcycledtl)'[TRC ICUFEECOMPONENT.FEE_COMPONENT_TYPE_ID]),
        'Breakdown Table (plancomcycledtl)'[TRC ICUFEECOMPONENT.FEE_COMPONENT_TYPE_ID] in {"0000011", "0000036", "0000075", "0000074", "0000073", "0000072", "0000078", "0000077"}
)
VAR NW_CHARGE_GROUP = CALCULATE(
        MAX('Breakdown Table (plancomcycledtl)'[TRC ICUFEECOMPONENT.FEE_COMPONENT_TYPE_ID]),
        FILTER('Breakdown Table (plancomcycledtl)', 'Breakdown Table (plancomcycledtl)'[TRC ICUFEECOMPONENT.FEE_COMPONENT_TYPE_ID] in {"0000002", "0000001", "0000004", "0000005", "0000006", "0000007", "0000008", "0000009", "0000010"})
)
RETURN
CALCULATE(
        SUM('Breakdown Table (plancomcycledtl)'[POS_NEG AMOUNTS]),
        'Breakdown Table (plancomcycledtl)'[TRC ICUFEECOMPONENT.FEE_COMPONENT_TYPE_ID] in {COC_TYPE_ID, NW_CHARGE_GROUP}
)
 
turp111_0-1699374477524.png

 

 
 
 

 

 

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @turp111 ,

You can create a measure or calculated column as below to get it, please find the details in the attachment.

Create a calculated column:

Column = 
VAR _mincid =
    CALCULATE (
        MIN ( 'Breakdown Table (plancomcycledtl)'[Child Comp ID] ),
        FILTER (
            ALLSELECTED ( 'Breakdown Table (plancomcycledtl)' ),
            'Breakdown Table (plancomcycledtl)'[Plan ID]
                = EARLIER ( 'Breakdown Table (plancomcycledtl)'[Plan ID] )
                && 'Breakdown Table (plancomcycledtl)'[Parent Component]
                    = EARLIER ( 'Breakdown Table (plancomcycledtl)'[Parent Component] )
        )
    )
VAR _pamount =
    CALCULATE (
        SUM ( 'Breakdown Table (plancomcycledtl)'[Comp Amount] ),
        FILTER (
            ALLSELECTED ( 'Breakdown Table (plancomcycledtl)' ),
            'Breakdown Table (plancomcycledtl)'[Plan ID]
                = EARLIER ( 'Breakdown Table (plancomcycledtl)'[Plan ID] )
                && 'Breakdown Table (plancomcycledtl)'[Parent Component]
                    = EARLIER ( 'Breakdown Table (plancomcycledtl)'[Parent Component] )
        )
    )
RETURN
    IF ( 'Breakdown Table (plancomcycledtl)'[Child Comp ID] = _mincid, _pamount )

vyiruanmsft_0-1701049130191.png

Create a mesaure:

Parent Amount = 
VAR _pid =
    SELECTEDVALUE ( 'Breakdown Table (plancomcycledtl)'[Plan ID] )
VAR _parentcmp =
    SELECTEDVALUE ( 'Breakdown Table (plancomcycledtl)'[Parent Component] )
VAR _ccid =
    SELECTEDVALUE ( 'Breakdown Table (plancomcycledtl)'[Child Comp ID] )
VAR _mincid =
    CALCULATE (
        MIN ( 'Breakdown Table (plancomcycledtl)'[Child Comp ID] ),
        FILTER (
            ALLSELECTED ( 'Breakdown Table (plancomcycledtl)' ),
            'Breakdown Table (plancomcycledtl)'[Plan ID] = _pid
                && 'Breakdown Table (plancomcycledtl)'[Parent Component] = _parentcmp
        )
    )
VAR _pamount =
    CALCULATE (
        SUM ( 'Breakdown Table (plancomcycledtl)'[Comp Amount] ),
        FILTER (
            ALLSELECTED ( 'Breakdown Table (plancomcycledtl)' ),
            'Breakdown Table (plancomcycledtl)'[Plan ID] = _pid
                && 'Breakdown Table (plancomcycledtl)'[Parent Component] = _parentcmp
        )
    )
RETURN
    IF ( _ccid = _mincid, _pamount )

vyiruanmsft_1-1701049273953.png

Best Regards

Community Support Team _ Rena
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

2 REPLIES 2
v-yiruan-msft
Community Support
Community Support

Hi @turp111 ,

You can create a measure or calculated column as below to get it, please find the details in the attachment.

Create a calculated column:

Column = 
VAR _mincid =
    CALCULATE (
        MIN ( 'Breakdown Table (plancomcycledtl)'[Child Comp ID] ),
        FILTER (
            ALLSELECTED ( 'Breakdown Table (plancomcycledtl)' ),
            'Breakdown Table (plancomcycledtl)'[Plan ID]
                = EARLIER ( 'Breakdown Table (plancomcycledtl)'[Plan ID] )
                && 'Breakdown Table (plancomcycledtl)'[Parent Component]
                    = EARLIER ( 'Breakdown Table (plancomcycledtl)'[Parent Component] )
        )
    )
VAR _pamount =
    CALCULATE (
        SUM ( 'Breakdown Table (plancomcycledtl)'[Comp Amount] ),
        FILTER (
            ALLSELECTED ( 'Breakdown Table (plancomcycledtl)' ),
            'Breakdown Table (plancomcycledtl)'[Plan ID]
                = EARLIER ( 'Breakdown Table (plancomcycledtl)'[Plan ID] )
                && 'Breakdown Table (plancomcycledtl)'[Parent Component]
                    = EARLIER ( 'Breakdown Table (plancomcycledtl)'[Parent Component] )
        )
    )
RETURN
    IF ( 'Breakdown Table (plancomcycledtl)'[Child Comp ID] = _mincid, _pamount )

vyiruanmsft_0-1701049130191.png

Create a mesaure:

Parent Amount = 
VAR _pid =
    SELECTEDVALUE ( 'Breakdown Table (plancomcycledtl)'[Plan ID] )
VAR _parentcmp =
    SELECTEDVALUE ( 'Breakdown Table (plancomcycledtl)'[Parent Component] )
VAR _ccid =
    SELECTEDVALUE ( 'Breakdown Table (plancomcycledtl)'[Child Comp ID] )
VAR _mincid =
    CALCULATE (
        MIN ( 'Breakdown Table (plancomcycledtl)'[Child Comp ID] ),
        FILTER (
            ALLSELECTED ( 'Breakdown Table (plancomcycledtl)' ),
            'Breakdown Table (plancomcycledtl)'[Plan ID] = _pid
                && 'Breakdown Table (plancomcycledtl)'[Parent Component] = _parentcmp
        )
    )
VAR _pamount =
    CALCULATE (
        SUM ( 'Breakdown Table (plancomcycledtl)'[Comp Amount] ),
        FILTER (
            ALLSELECTED ( 'Breakdown Table (plancomcycledtl)' ),
            'Breakdown Table (plancomcycledtl)'[Plan ID] = _pid
                && 'Breakdown Table (plancomcycledtl)'[Parent Component] = _parentcmp
        )
    )
RETURN
    IF ( _ccid = _mincid, _pamount )

vyiruanmsft_1-1701049273953.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Rupak_bi
Resolver II
Resolver II

Hae you tried calculate sum of amount filtering all (child IDs)  ??

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.