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
dp106
Helper I
Helper I

Display grand total and average in each row (direct query)

Hi,

 

I am using direct query. I need the grant total and average to be displayed in each row. is it possible. ? i know i can do this in sql but i dont want to.

 

Here is an example

 

Col1   Col2  Sum   Avg

X        100   600    200

Y        200   600    200

Z        300   600    200

 

Thanks

 

 

 

 

 

1 ACCEPTED SOLUTION

Hi @dp106,

 

Just see your data here, please try the formulas below.

Avg = 
CALCULATE ( AVERAGE ( 'table'[Col2] ), ALL ( 'Table'[Col1], 'Table'[Col2] ) )
Sum = 
CALCULATE ( SUM ( 'table'[Col2] ), ALL ( 'Table'[Col1], 'Table'[Col2] ) )

Display_grand_total_and_average_in_each_row_direct_query

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-jiascu-msft
Employee
Employee

Hi @dp106,

 

Could you please mark the proper answer as a solution?

 

Best Regards,
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-jiascu-msft
Employee
Employee

Hi @dp106,

 

You can create two measures like below.

Avg =
CALCULATE ( AVERAGE ( 'table'[Col2] ), ALL ( 'table' ) )
Sum =
CALCULATE ( SUM ( 'table'[Col2] ), ALL ( 'table' ) )

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks. The solution seems to be working fine but not if i have filters (slicers on the reports).


If i add the mesaure, no matter what filters are applied in the report, all the values are pulled from the database.

 

Here is how the data is. i have a slicer on the report on col0 (there are couple of filters on the actual report)


Col0 Col1   Col2  Sum   Avg

1 X        100   600    200
1 Y        200   600    200
1 Z        300   600    200

 

2 X        150   900    300
2 Y        500   900    300
2 Z        250   900    300

 

Thanks again for looking at it.

Just need to modify the ALL, which as you'd expect is pulling all the data, to using ALLEXCEPT and specifying Col0 as needed. It will pull through all the values in your database as is, as that's what you're telling it to do...

Thanks for your response.

I tried the solution you recommended, so the calculation works fine but it pulls are the records from the database (ignoring the slicer)

 

Hi @dp106,

 

Just see your data here, please try the formulas below.

Avg = 
CALCULATE ( AVERAGE ( 'table'[Col2] ), ALL ( 'Table'[Col1], 'Table'[Col2] ) )
Sum = 
CALCULATE ( SUM ( 'table'[Col2] ), ALL ( 'Table'[Col1], 'Table'[Col2] ) )

Display_grand_total_and_average_in_each_row_direct_query

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.