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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

DAX measure for sum of average by grouping

Hi everyone, I'm looking for help creating this DAX measure after spending some time trying my own solutions and search online for something similar, to no avail. Here what my starting table looks like:

 

GroupYearYear-QuarterValue
A12019

2019Q3

30
A120192019Q430
A120202020Q140
A22019

2019Q3

3
A220192019Q43
A220202020Q14

B1

2019

2019Q3

20
B120192019Q420
B120202020Q130

 

For a given Group, for a given Year, the Value field will be duplicated for each quarter. I need to create a measure that gives my the sum of the Value column by each unique Year-Group combo. The simplest example is if I have a slicer with A1 selected and a date slider filtering on 2019Q3-2019Q4, the DAX measure should output 30. A slightly more complicated example is if I have a slicer filtering for A1 and A2, and a date slider with 2019Q3-2019Q4 selected, the measure should output 33, since that is the sum of the unique Year-Group values. I've tried all manner of CALCULATE, SUMX, and GROUPBY statements and really am not getting anywhere. Any ideas? I'm sure there is a simple answer, thanks!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

 

SUMX(
	SUMMARIZE(
		FT,
		FT[Group],
		FT[Year]
	),
	CALCULATE(
		SUMX(
			VALUES( FactTable[Value] ),
			FactTable[Value]
		)
	)
)

 

 

Even though the above works, I'm afraid it could sometimes return incorrect results. Anything (the above formula from Greg included) that you calculate on a single fact table CAN return an incorrect result as the below article explains:

 

https://www.sqlbi.com/articles/understanding-dax-auto-exist/

 

Therefore, you should create a star-schema as the model for your data. Don't do it and you'll be creating wrong figures you will not even be aware of.

 

If your model is correct, then this will do what you want:

 

 

SUMX(
	SUMMARIZE(
		FT,
		Groups[Group],
		Calendar[Year]
	),
	CALCULATE(
		SUMX(
			VALUES( FactTable[Value] ),
			FactTable[Value]
		)
	)
)

 

 

Best

D

View solution in original post

3 REPLIES 3
Greg_Deckler
Super User
Super User

I would think:

 

Measure =
VAR __Table = 
  SUMMARIZE(
    'Table',
    [Group],
    [Year],
    "Value",AVERAGE([Value])
  )
RETURN
  SUMX(__Table,[Value])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

 

SUMX(
	SUMMARIZE(
		FT,
		FT[Group],
		FT[Year]
	),
	CALCULATE(
		SUMX(
			VALUES( FactTable[Value] ),
			FactTable[Value]
		)
	)
)

 

 

Even though the above works, I'm afraid it could sometimes return incorrect results. Anything (the above formula from Greg included) that you calculate on a single fact table CAN return an incorrect result as the below article explains:

 

https://www.sqlbi.com/articles/understanding-dax-auto-exist/

 

Therefore, you should create a star-schema as the model for your data. Don't do it and you'll be creating wrong figures you will not even be aware of.

 

If your model is correct, then this will do what you want:

 

 

SUMX(
	SUMMARIZE(
		FT,
		Groups[Group],
		Calendar[Year]
	),
	CALCULATE(
		SUMX(
			VALUES( FactTable[Value] ),
			FactTable[Value]
		)
	)
)

 

 

Best

D

Anonymous
Not applicable

Excellent, this works perfectly. Regarding the model, this table is being sliced by a series of master tables in a star format so I think there should be no issues there. I'm still learning about how to build good data relationships and DAX as well so all of this is helpful! DAX measures in particular are difficult to wrap my head around...

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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