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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Stuck with simple aggreagte of aggregates

I'm trying to do a simple calculation but stuck on aggregating data that is already aggregated.
I have a raw table of multiple rows per Pupil, with a value for each Test they've say.

I've added a MEASURE:
AvRes=Average(TEST[result])

And so in a table viz, can show PUPIL and AvRes.

I'm working towards a correlation coefficient so now want to Sum the AvRes for all the selected* Pupils (*they may have been filtered).
How can I add a measure to the table showing the SUM of all the AvRes values (for the selected pupils - ie. the ones in the table viz).  This must be simple, but I'm stumped.

 

8 REPLIES 8
DataInsights
Super User
Super User

@Anonymous, I think this is the DAX pattern you want. If the output isn't what you're envisioning, we can tweak it to meet the requirements.

 

Measure:

 

Sum AvRes = 
VAR vTestResultTable =
    ADDCOLUMNS ( VALUES ( TestResult[Pupil] ), "AvRes", [AvRes] )
VAR vResult =
    SUMX ( vTestResultTable, [AvRes] )
RETURN
    vResult

 

DataInsights_0-1600126315795.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

Thanks for your reply - looks like I'm nearly there...

Your formula works fine when the measure is dragged onto a card (i.e. a summary), but isn't summarizing when added to a table viz.

I need to be able to display like this:

 

PupilAvRes (measure)SumAvRes
Person182162
Person280162

 

But currently, that formula will group by the row, so it just duplicates the AvRes value - like this:

PupilAvRes (measure)SumAvRes
Person18282
Person28080

I tried using ALLSELECTED:

 

VAR vResult = SUMX ( ALLSELECTED(vTestResultTable), [AvRes] )

 

but that expects a table reference.

So close.... 

@Anonymous, you're on the right path with ALLSELECTED. The missing piece was CALCULATE, which is necessary to override the filter context coming from the Pupil field in the table visual.

 

Sum AvRes = 
VAR vTestResultTable =
    ADDCOLUMNS ( ALLSELECTED ( TestResult[Pupil] ), "AvRes", [AvRes] )
VAR vResult =
    CALCULATE (
        SUMX ( vTestResultTable, [AvRes] ),
        ALLSELECTED ( TestResult[Pupil] )
    )
RETURN
    vResult

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

Thanks again...but this still isn't working for me in a Table viz, I'm getting the following with the new measure:

PupilAvResSum AvRes
Person18282
Person28080

It works a treat when I add the new measure to a card, but in a table (and therefore in any further calcs) it's not applying to the WHOLE table for some reason.  This is baffling me.  

@Anonymous, is the same Pupil column being used in both the slicer and table visual? Could you upload a pbix so I can troubleshoot?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

So, I've got this working (using your suggested solution (thank you).

I stripped it back to a handful of rows and a single table, and it worked fine, which I couldn't understand.

Then I realised a subtle difference to how I was set up.

Previously "Pupil" was in a related Table, not in the source table for the Measure:

EnateJon_0-1600276942692.png

Is there some logic behind this ?

 

Anonymous
Not applicable

And...even is I add a calculated column relPupil=Related(Pupil[Pupil]), so it is in the source, I get the same problem.  Which would suggest all the normalised data needs to be in the source table.  That seems kind of limiting?  Any way roundf this?

Hi @Anonymous,

 

Using a Star Schema is the best approach with Power BI, you would just need change the table you are iterating through with your SUMX. Assuming a Pupil Table and Results table the following should provide the desired results.

 

Avg Results = AVERAGE(Results[Score])

Sum of Averages = CALCULATE(SUMX('Pupil', [Avg Results]), ALLSELECTED(Pupil))

 

richbenmintz_0-1600278960684.png

Hope this Helps,
Richard


Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!



I hope this helps,
Richard

Did I answer your question? Mark my post as a solution! Kudos Appreciated!

Proud to be a Super User!


Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.