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
Anonymous
Not applicable

Sum of averages from a column

Hi All,

 

I have a dataset as below :

CityTotal lenght in Kms
London80
London80
Paris50
Paris50
Paris50
Paris50

 

I have a card display where I need to show the average of lenght when a city is selected. Which I have acheived by averaging on a selected city. However, if two cities are selected it is adding up both the cities length and averaging on it. Ex : (50+80)/2 = 65

I need to perform an average on both cities seperately and add up the averages. 

Ex : 50 + 80 = 130. How do I achieve it?  

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

usure why this is not working for me, the city and lenght are from calculated tables. I tried changing the lenght in mts to a measure, but still not working :

var single = CALCULATE(AVERAGEX(Table, VALUES(Table[city])),[AveTLeninKms])
var multi = SUMX(VALUES(Table[city]), single)
return multi
 
error :A function 'CALCULATE' has been used in a True/False expression that is used as a table filter expression. This is not allowed

View solution in original post

not quite the same. try this:

 

VAR single=CALCULATE(AVERAGEX(VALUES('Table'[AveTLeninKms]),'Table'[AveTLeninKms]))
VAR multi=SUMX(VALUES('Table'[City]),single)
RETURN
multi
// if this is a solution please mark as such. Kudos always appreciated.

View solution in original post

5 REPLIES 5
samdthompson
Memorable Member
Memorable Member

hello, try something like this:

 

SumAvg=

VAR single=CALCULATE(AVERAGEX(VALUES(Table1[City]),Table1[Distance]))

VAR multiple=SUMX(VALUES(Table1[City]),single)

RETURN

multiple

 

2021-04-22_14-34-17.jpg

2021-04-22_14-35-49.jpg

 

// if this is a solution please mark as such. Kudos always appreciated.
Anonymous
Not applicable

usure why this is not working for me, the city and lenght are from calculated tables. I tried changing the lenght in mts to a measure, but still not working :

var single = CALCULATE(AVERAGEX(Table, VALUES(Table[city])),[AveTLeninKms])
var multi = SUMX(VALUES(Table[city]), single)
return multi
 
error :A function 'CALCULATE' has been used in a True/False expression that is used as a table filter expression. This is not allowed

not quite the same. try this:

 

VAR single=CALCULATE(AVERAGEX(VALUES('Table'[AveTLeninKms]),'Table'[AveTLeninKms]))
VAR multi=SUMX(VALUES('Table'[City]),single)
RETURN
multi
// if this is a solution please mark as such. Kudos always appreciated.
Anonymous
Not applicable

This works, thanks!

no worries. it was the 'Table' vs Table that was off

// if this is a solution please mark as such. Kudos always appreciated.

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.