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
aloosh89
Helper I
Helper I

Perform summation and average on subset of IDs based on occurence of attribute

Hello,

 

Consider the table below

 

IDAttributeValue
1A10
1B10
1C10
2A10
2B10
2C10
3B10
3C10
3D10

 

I would like to sum up the Vales of the column 'Value' but only for ID's for which the attribute 'A' appears. For the above table the desired output would be:

 

IDDesired ouptut 1
130
230

 

And finally a second ouptut I want is to be able to sum this 'deisred output 1' and dived by the count of the IDs. Hence in this case (30+30)/2 = 30 = Desired ouptut 2

 

Thanks for any help in advance

Ali 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @aloosh89 ,

 

I suggest you to try code as below to create measures.

Desired ouptut 1 = 
VAR _IDLIST =
    CALCULATETABLE ( VALUES ( 'Table'[ID] ), 'Table'[Attribute] = "A" )
RETURN
    SUMX ( FILTER ( 'Table', 'Table'[ID] IN _IDLIST ), [Value] )
Desired ouptut 2 =
AVERAGEX ( VALUES ( 'Table'[ID] ), [Desired ouptut 1] )

Result is as below.

vrzhoumsft_0-1697707398909.png

 

Best Regards,
Rico Zhou

 

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
Anonymous
Not applicable

Hi @aloosh89 ,

 

I suggest you to try code as below to create measures.

Desired ouptut 1 = 
VAR _IDLIST =
    CALCULATETABLE ( VALUES ( 'Table'[ID] ), 'Table'[Attribute] = "A" )
RETURN
    SUMX ( FILTER ( 'Table', 'Table'[ID] IN _IDLIST ), [Value] )
Desired ouptut 2 =
AVERAGEX ( VALUES ( 'Table'[ID] ), [Desired ouptut 1] )

Result is as below.

vrzhoumsft_0-1697707398909.png

 

Best Regards,
Rico Zhou

 

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

amitchandak
Super User
Super User

@aloosh89 , Try a measure like

 


Measure =
var _1 = countrows(filter(Table, Table[Attribute] ="A"))
return
Sumx(Filter(Values(Table[ID]), not(isblank(_1 ))), calculate(Sum(Table[Value])))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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!

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