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

View all the Fabric Data Days sessions on demand. View schedule

Reply
Anonymous
Not applicable

Distinct Sum Then average in Measure

I need to create a measure to distinct Sum the value by ID and show average in the total. 

 

IDCodeValueQuantity 
1A10010
1B20012
1B20014
1B20016
2A50018
2A50020
2B80022
2B80024


Finally result:

 IDValue
 1300
 21300
Total 800




1 ACCEPTED SOLUTION
bcdobbs
Community Champion
Community Champion

Hi Eric,

 

Try the following:

 

DistinctSum = 

VAR DistinctTableSum = 
	ADDCOLUMNS (
		VALUES ( ExampleTable[ID] ),
		"@SumColumn", CALCULATE (SUMX ( VALUES ( ExampleTable[Value] ), ExampleTable[Value] ) )
		)

VAR Result =
    AVERAGEX (
        DistinctTableSum,
        [@SumColumn]
    )

RETURN Result


Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

View solution in original post

4 REPLIES 4
bcdobbs
Community Champion
Community Champion

Hi Eric,

 

Try the following:

 

DistinctSum = 

VAR DistinctTableSum = 
	ADDCOLUMNS (
		VALUES ( ExampleTable[ID] ),
		"@SumColumn", CALCULATE (SUMX ( VALUES ( ExampleTable[Value] ), ExampleTable[Value] ) )
		)

VAR Result =
    AVERAGEX (
        DistinctTableSum,
        [@SumColumn]
    )

RETURN Result


Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!
Anonymous
Not applicable

Thanks Ben, It do help a lot.  Finally I also figured it out. This is my formula for your reference. Please feel free to give me some advice 

DistinctSum_average =
VAR a_ =
SUMMARIZE (
Sheet1,
Sheet1[ID],
Sheet1[Code],
"average", AVERAGE ( Sheet1[Value] )
)
RETURN
IF (
HASONEFILTER ( Sheet1[ID] ),
SUMX ( a_, [average] ),
DIVIDE ( SUMX ( a_, [average] ), DISTINCTCOUNT ( Sheet1[ID] ) )
)

Glad you've got it working!

 

Have a read of: https://www.sqlbi.com/articles/all-the-secrets-of-summarize/

They strongly advise using addcolumns in conjunction with summarise.



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!
Anonymous
Not applicable

Relly appreciate

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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
Top Kudoed Authors