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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

How to group and sum row values over other columns in Power BI desktop

Hi Experts,

 

I am new to Power BI dax and trying to achieve below but couldn't succeed. Could you please help?

 

Problem: I want to group the rows by Start_date, Location, headline, Unit and sum the first_impact and second impact. While summing the rows, i want to display row having higher Plan Code.

Note: First_Impact and Second_Impact has been calcuated in separate measure using user input slicer filters.

 

Start_datePlanPlan CodeLocationheadlineUnitPriorityFirst_ImpactSecond_ImpactTotal Impact
1/1/2021Dom15Site_1Air limitD_Other GDCFALSE0.000.470.47
1/1/2021Test Planned8Site_1This is heaterMy_PokerFALSE0.010.000.01
1/1/2021Planned10Site_1This is heaterMy_PokerTRUE0.060.000.06
1/1/2021Planned10Site_2safety regulationGe_CycleFALSE0.040.000.04
1/1/2021Unplanned5Site_2limitations trainGe_B12TRUE0.020.000.02

 

Below is what i want to achieve:

 

Start_datePlanPlan CodeLocationheadlineUnitPriorityFirst_ImpactSecond_ImpactTotal Impact
1/1/2021Dom15Site_1Air limitD_Other GDCFALSE0.000.470.47
1/1/2021Planned10Site_1This is heaterMy_PokerTRUE0.070.000.07
1/1/2021Planned10Site_2safety regulationGe_CycleFALSE0.040.000.04
1/1/2021Unplanned5Site_2limitations trainGe_B12TRUE0.020.000.02
1 ACCEPTED SOLUTION

Hi @Anonymous 

try this :

Measure_First_impact =
VAR _group =
    FILTER(
        ALL( 'Table' ),
        // [Start_date] = MAX( 'Table'[Start_date] )
        // && 
        [Location]
            = SELECTEDVALUE( 'Table'[Location] )
            && [Unit] = SELECTEDVALUE( 'Table'[Unit] )
            && [headline] = SELECTEDVALUE( 'Table'[headline] )
    )
VAR _sum =
    SUMX( _group, [First_Impact] )
VAR _maxcode =
    CALCULATE( MAX( 'Table'[Plan Code] ), _group )
RETURN
    IF( MAX( 'Table'[Plan Code] ) = _maxcode, _sum, BLANK() )

vchenwuzmsft_0-1634723896130.png

Best Regards

Community Support Team _ chenwu zhu

 

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

8 REPLIES 8
v-chenwuz-msft
Community Support
Community Support

Hi @Anonymous ,

 

Try these measures to replace first, sencond and total impact.

 

Measure_First_impact =
VAR _group =
    FILTER(
        ALL( 'Table' ),
        [Start_date] = MAX( 'Table'[Start_date] )
            && [Location] = SELECTEDVALUE( 'Table'[Location] )
            && [Unit] = SELECTEDVALUE( 'Table'[Unit] )
    )
VAR _sum =
    SUMX( _group, [First_Impact] )
VAR _maxcode =
    CALCULATE( MAX( 'Table'[Plan Code] ), _group )
RETURN
    IF( MAX( 'Table'[Plan Code] ) = _maxcode, _sum, BLANK() )
Measure_Second_impact =
VAR _group =
    FILTER(
        ALL( 'Table' ),
        [Start_date] = MAX( 'Table'[Start_date] )
            && [Location] = SELECTEDVALUE( 'Table'[Location] )
            && [Unit] = SELECTEDVALUE( 'Table'[Unit] )
    )
VAR _sum =
    SUMX( _group, [Second_Impact] )
VAR _maxcode =
    CALCULATE( MAX( 'Table'[Plan Code] ), _group )
RETURN
    IF( MAX( 'Table'[Plan Code] ) = _maxcode, _sum, BLANK() )
Measure_Total_impact = [Measure_First_impact]+[Measure_Second_impact]

 

result:

vchenwuzmsft_0-1634030501128.png

I put my pbix file in the end and you can reference. If I misunderstood you please let me know.

 

 

Best Regards

Community Support Team _ chenwu zhu

 

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

Anonymous
Not applicable

@v-chenwuz-msft : Many thanks for your inputs! The solution works only if we have only single start_date. I have tried your solution with below data and it didn't gave any values for first and second impact. Pls correct me, if I am missing something here.

 

Start_datePlanPlan CodeLocationheadlineUnitPriorityFirst_impactSecond_impactTotal Impact
1/1/2021Dom15Site_1Air limitD_Other GDCFALSE00.470.47
1/1/2021Planned10Site_1This is heaterMy_PokerTRUE0.0600.06
1/1/2021Test Planned8Site_1This is heaterMy_PokerFALSE0.0100.01
1/1/2021Unplanned5Site_2limitations trainGe_B12TRUE0.0200.02
1/1/2021Planned10Site_2safety regulationGe_CycleFALSE0.0400.04
1/3/2021Unplanned5Site_1limitations trainGe_B12FALSE0.020.010.03
1/3/2021Planned10Site_1limitations trainGe_B12TRUE0.030.040.07
1/3/2021Unplanned5Site_1limitations trainGe_B12FALSE0.010.010.02
2/4/2021Planned10Site_2safety regulationMy_PokerFALSE235
2/4/2021Dom15Site_2safety regulationMy_PokerTRUE516

 

 

Expected output:

Start_datePlanPlan CodeLocationheadlineUnitPriorityFirst_impactSecond_impactTotal Impact
1/1/2021Dom15Site_1Air limitD_Other GDCFALSE00.470.47
1/1/2021Planned10Site_1This is heaterMy_PokerTRUE0.0700.07
1/1/2021Planned10Site_2safety regulationGe_CycleFALSE0.0400.04
1/3/2021Unplanned10Site_1limitations trainGe_B12TRUE0.080.060.14
2/4/2021Dom15Site_2safety regulationMy_PokerTRUE7411

 

Hi @Anonymous ,Can you explain why 1/3/2021 first_impact is 0.08, it is added to the 0.02 in the fourth line to get it? If so, your grouping should be based on location,headline, unit. without the start_date . However, the location in the fourth line is Site_2, which is not the same as the location of 1/3/2021. Please let me know if I have misunderstood.

Anonymous
Not applicable

@v-chenwuz-msft: My sincere apologies, there is a correction in the expected output (see corrected output below).

Please note, the requirement is:

1. First_Impact, Second_Impact and Total Impact are getting calculated over -> Start_date, Location, headline, Unit )). Then, displaying the row where Plan Code is maximum.

 

 

Start_datePlanPlan CodeLocationheadlineUnitPriorityFirst_impactSecond_impactTotal Impact
01-01-2021Dom15Site_1Air limitD_Other GDCFALSE00.470.47
01-01-2021Planned10Site_1This is heaterMy_PokerTRUE0.0700.07
01-01-2021Unplanned5Site_2limitations trainGe_B12TRUE0.0200.02
01-01-2021Planned10Site_2safety regulationGe_CycleFALSE0.0400.04
01-03-2021Planned10Site_1limitations trainGe_B12TRUE0.060.060.12
02-04-2021Dom15Site_2safety regulationMy_PokerTRUE7411

Hi @Anonymous 

try this :

Measure_First_impact =
VAR _group =
    FILTER(
        ALL( 'Table' ),
        // [Start_date] = MAX( 'Table'[Start_date] )
        // && 
        [Location]
            = SELECTEDVALUE( 'Table'[Location] )
            && [Unit] = SELECTEDVALUE( 'Table'[Unit] )
            && [headline] = SELECTEDVALUE( 'Table'[headline] )
    )
VAR _sum =
    SUMX( _group, [First_Impact] )
VAR _maxcode =
    CALCULATE( MAX( 'Table'[Plan Code] ), _group )
RETURN
    IF( MAX( 'Table'[Plan Code] ) = _maxcode, _sum, BLANK() )

vchenwuzmsft_0-1634723896130.png

Best Regards

Community Support Team _ chenwu zhu

 

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

Anonymous
Not applicable

@v-chenwuz-msft It worked!! Thanks you so much 🙂

Fowmy
Super User
Super User

@Anonymous 

Following table shoudl give yo the expected results:

FILTER (
    ADDCOLUMNS (
        Table1,
        "@First Impact", [First Impact],
        "@Second Impact", [Second Impact],
        "@Total Impact", [Total Impact]
    ),
    VAR _PlanCode =
        CALCULATE (
            MAX ( Table1[Plan Code] ),
            ALLEXCEPT (
                Table1,
                Table1[Start_date],
                Table1[Location],
                Table1[headline],
                Table1[Unit]
            )
        )
    RETURN
        Table1[Plan Code] = _PlanCode
)
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

@Fowmy Thanks for your reply. The output I am getting is little different from expected. I want to sum up the values of first impact and second impact rows over start_date, location, headline and unit. Hence, the value should be 0.07 (0.06+0.01) in the highlighted row.

 

negis_0-1633940483961.png

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.

Top Solution Authors