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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Average over entire column in DAX measure when filtered

Hi,

 

I am using a "Line and clustered column chart" and would like to add an additional line to dsiplay the average value of one of the columns. I have written a DAX measure that pefectly calculates me the value that I want to see and I can use it on cards etc. However as soon as I put the measure on the chart, it is being calculated for each category on the x-axis again. Here is the structure of the measure that I use - it sums up values in a table (Table1) based on a filter in another table (Table2) and then divides by the number of selected entries in Table2.:

 

avg_activity = 
VAR sumofactivity = 
CALCULATE(
	SUM('Table1'[Activity]);
	'Table2'[Type] IN { "mytype" }
)
RETURN
VAR countofactivity =
CALCULATE(COUNTROWS(Table2);'Table2'[Type] IN { "mytype" })
RETURN
sumofactivity/countofactivity

 

The month year hierachy on the x-axis is also from Table2, the values on the chart are from Table1. Now what I would like to get when putting this measure on a the chart wozuld be something like this: 

image.png

but what I get looks like this:

image.png

I've also tried using caluclated columns but with no success. I know that the problem is me using the Calculate-Function wrong but would be very thankful for any hint on how to get the desired behaviour!

 

2 REPLIES 2
Greg_Deckler
Super User
Super User

Perhaps:

 

avg_activity = 
VAR sumofactivity = 
CALCULATE(
	SUMX(ALL('Table1'),[Activity]);
	'Table2'[Type] IN { "mytype" }
)
RETURN
VAR countofactivity =
CALCULATE(COUNTROWS(ALL(Table2));'Table2'[Type] IN { "mytype" })
RETURN
sumofactivity/countofactivity

@ 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!:
The Definitive Guide to Power Query (M)

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

Hi Greg, thanks for your quick response! Unfortunately that creates a value which is way too high, however at least it displays now a constant line, so I think you showed me the right track.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors