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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
EHa
Helper I
Helper I

Sum over filtered values and replace total with average

Hello all! 

 

I have found lots of similar answers to similar questions on the forums already, but none seem to work so hoping someone could help me out.

I have the following matrix visualisation which I use drop down menus to filter.

TestDataMatrix.PNG

 

I wish to compare the different runs, which make up my column variable, and then filter those by my other variables for more detail. I would mainly like my total column to be replaced by an averages column and then have additional columns side by side with the differences between that run and the average. 

I understand the basics of measures and have had plenty of attempts at making my own average column, but when I use DAX like:

SumOverRun = Calculate(SUM(TestData[Value]),TestData[Run])
It sums over all runs, even when I have used the dropdowns to filter away some of them.
Once I have figured out how to sum over just the filtered values it seems relatively simple to calculate the average using countrows(distinct)
, and then subtracting the values away from that, before using conditional formatting to colour these differences, but if anyone has insight on issues I may face,
that would be appreciated too!
 
Thanks,
EHa
 

 

 

 

1 ACCEPTED SOLUTION

Going to drop my solution in here ion case anyone with a similar problem comes across it in the future:

For me it was as simple as :

TotalSum  = Sum(TableName[Value])

RunsSelected = Countrows(Distinct(AllSELECTED(TableName[Runs])))

SumOverRuns = Calculate( [TotalSum] , ALLSELECTED(TableName[Runs]))

AverageOverRuns = Divide(SumOverRuns , RunsSelected)

 

 

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@EHa , is filtered or is in scope should help

https://powerpivotpro.com/2013/03/hasonevalue-vs-isfiltered-vs-hasonefilter/

 

or see this formula can help

averageX(summarize(table,table[location], table[stat],"_1",Calculate(SUM(TestData[Value]),TestData[Run])) ,[_1])
Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi @amitchandak ,

Thanks for the quick reply , I will definitely have a proper explore of the isfiltered function today.

I did try your test code (with both table and testdata changed to Sheet1 ,which is the name of the table in my report at the moment)

It doesn't seem to do what I want however: 

testdata1.PNG

Idon't fully understand what it is doing in every position, but it seems to do exactly what I want for London and Paris totals, but not for the Mean and SD as it is dividing the totals by 1 and not 2. Is there a way to slightly edit this so it works do you think? 

Additionally, once this is done, is there a way to only keep the final column / turn the others to differences?

Thanks a lot for your help,

EHa

Going to drop my solution in here ion case anyone with a similar problem comes across it in the future:

For me it was as simple as :

TotalSum  = Sum(TableName[Value])

RunsSelected = Countrows(Distinct(AllSELECTED(TableName[Runs])))

SumOverRuns = Calculate( [TotalSum] , ALLSELECTED(TableName[Runs]))

AverageOverRuns = Divide(SumOverRuns , RunsSelected)

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.