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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

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
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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