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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Alfista1997
Frequent Visitor

Subtotal Column Based on Aggregate of Another Column by Groups

I have some data where I essentially want to find the sum of a column, based on another column's average value. So for example, for each ID, I'm wanting to average the 'Value' column and if that averaged value is less than 0, then it is excluded/made to be $0 in the subsequent aggregation; otherwise, sum the 'Dollar' for that ID. The orange table is the kind of output I'm looking for from a measure.

 

Table Example.jpg

 

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@Alfista1997 change column names as per your table

 

Sum = 
VAR __Table = 
ADDCOLUMNS ( 
    SUMMARIZE ( 
        'Table', 
        'Table'[PDNCON], 
        'Table'[ACTIVITY_YEARS] 
    ), 
    "@Avg", CALCULATE ( AVERAGE ( 'Table'[FP_OS] ) ), 
    "@Sum", CALCULATE ( SUM ('Table'[SSNARNET] ) ) 
)
RETURN 
SUMX ( FILTER ( __Table, [@Avg] > 0 ), [@Sum] )

parry2k_0-1693361670192.png

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

7 REPLIES 7
parry2k
Super User
Super User

@Alfista1997 change column names as per your table

 

Sum = 
VAR __Table = 
ADDCOLUMNS ( 
    SUMMARIZE ( 
        'Table', 
        'Table'[PDNCON], 
        'Table'[ACTIVITY_YEARS] 
    ), 
    "@Avg", CALCULATE ( AVERAGE ( 'Table'[FP_OS] ) ), 
    "@Sum", CALCULATE ( SUM ('Table'[SSNARNET] ) ) 
)
RETURN 
SUMX ( FILTER ( __Table, [@Avg] > 0 ), [@Sum] )

parry2k_0-1693361670192.png

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

This is perfect, thanks!
Ashish_Mathur
Super User
Super User

Hi,

These measures work

Average value = AVERAGE(Data[Value])
D = SUM(Data[Dollar])
Measure = AVERAGEX(FILTER(VALUES(Data[ID]),[Average value]>0),[D])

Hope this helps.

Ashish_Mathur_0-1693353361408.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur, my apologies, I probably provided a poor sample set. I've put a small extract of my data below, but still can't get this to work as I'd expect. The total as shown in the screenshot, should be the subtotal of only PDN 10018 and 11947, since the average of 91662's 'NET_FP_OS' is <0. So if the average of 'NET_FP_OS' is <0, don't sum it's corresponding 'CONS_SSNAR' value.

 

Table Example3.jpg

 

ACTIVITY_YEARPDNCONS_SSNARNET_FP_OS

20230510018$4,995,991$15,057,228
20230610018$6,324,033$18,150,364
20230710018$6,254,358$21,590,385
20230511947$3,735,055$19,083,524
20230611947$3,919,154$18,116,915
20230711947$2,819,271$11,633,517
20230591662$606,770($3,001,285)
20230691662$710,005($2,990,821)
20230791662$902,712($1,588,642)

I still do not understand.  Share the download link of your MS Excel file with your formulas already written there.  I will translate those formulas into the DAX language.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
parry2k
Super User
Super User

@Alfista1997 try this measure:

 

Sum of Dollar Based on Avg = 
VAR __Table = ADDCOLUMNS ( Test, "@Avg", AVERAGE ( Test[Value] ) )
RETURN 
SUMX ( FILTER ( __Table, [@Avg] > 0 ), [Dollar] )


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k, I'm probably missing something or poorly explained, but this doesn't seem to be working exactly the way I'm thinking.

 

I've attached a better example of my data below.. The total as shown in the screenshot, should be the subtotal of only PDN 10018 and 11947, since the average of 91662's 'NET_FP_OS' is <0. So if the average of 'NET_FP_OS' is <0, don't sum it's corresponding 'CONS_SSNAR' value.

 

ACTIVITY_YEARPDNCONS_SSNARNET_FP_OS

20230510018$4,995,991$15,057,228
20230610018$6,324,033$18,150,364
20230710018$6,254,358$21,590,385
20230511947$3,735,055$19,083,524
20230611947$3,919,154$18,116,915
20230711947$2,819,271$11,633,517
20230591662$606,770($3,001,285)
20230691662$710,005($2,990,821)
20230791662$902,712($1,588,642)

 

Table Example2.jpg

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.