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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Gutenvirt
Frequent Visitor

CALCULATE and filtering by aggregate comparison

I'm new to Power Bi and DAX but I have some familarity with Excel and Tableau.  

 

In any event, I'd like to use the CALCULATE function to find the average of some column if the the average of another column is equal to the average of another column.

 

I tried:

 

InRange= CALCULATE(AVERAGE(tbl2[percent]),AVERAGE(tbl2[num_partic])=AVERAGE(tbl_input[num_build]))

 

It gives an error about True/False expressions (which I'd assume means it can equate two aggregate functions)

 

Ideally I'd have a predetermined tolerance of about +/- 15% but I can work on that if I get the above working.  Any  help woudl be greatly appreciated!

3 REPLIES 3
Greg_Deckler
Super User
Super User

At first I thought you might need a filter clause but now I can't quite wrap my head around what you are trying to do and I think it is because of the relationships perhaps. tbl2 must be related to tbl_input, correct? This is a measure, correct? What happens if the averages don't equal one another? Can you just use an IF statement:

 

IF(AVERAGE(tbl2[num_partic])=AVERAGE(tbl_input[num_build]),AVERAGE(tbl2[percent]),"FALSE")

 

?

 

 


@ 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...

Sorry, I should have provided a bit of context.  I'm looking at an NCEA dataset about school districts.  Here is a sample of the data:

 

districtrndstrationum_schsclsrm_tch_ftenum_stds
Alachua1672180428157
Baker1693124985
Bay1551179427053
Bradford13122433239
Brevard15128472371232

 

 

My intent was to create a report that lists schools with a similar number of schools (+/- 15%)  So if I select Alachua from a slicer, I would display the average number of students for all district that have between 62 and 83 schools.

 

I hope this helps; if the 'if' statements you mentioned might make this work.  Thanks!

 

@Gutenvirt - OK, someone else may have a more brilliant solution to this but perhaps this is something that you can build off or get an idea from. I took your table and imported it twice, Schools and Schools2. To both I added a custom column:

 

Category = IF(Schools2[num_schs]<40,"Small",IF(Schools2[num_schs]<100,"Medium","Large"))

And created a Category list via Enter Data with Small Medium and Large as values in a Category column. Related both School tables to Category table, put district from School table in a slicer and added all of the data from School2 to a table. Clicking on the district slicer then filters the Schools2 table to only the districts in the same category.


@ 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...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.