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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Anonymous
Not applicable

How to find the average in the group

roopesh_0-1599016214586.png

i want the average in the form

eg: cellular Therapy (39+15+4)/3(Years)

Can anyone help me out with this?

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

 

[Within-Group Avg over Years] =
// T is the name of the table;
// This measure will return
// a number if only one group is
// visible in the current context.
var __currentGroup = selectedvalue( T[StudyGroup] )
var __result =
    calculate(
        averagex(
            values( T[Year] ),
            [AVGSdgGroupMeasure]
        ),
        T[StudyGroup] = __currentGroup,
        // This directive makes it
        // a visual calculation.
        allselected( T )
    )
return
    __result

 

View solution in original post

19 REPLIES 19
Anonymous
Not applicable

 

[Within-Group Avg over Years] =
// T is the name of the table;
// This measure will return
// a number if only one group is
// visible in the current context.
var __currentGroup = selectedvalue( T[StudyGroup] )
var __result =
    calculate(
        averagex(
            values( T[Year] ),
            [AVGSdgGroupMeasure]
        ),
        T[StudyGroup] = __currentGroup,
        // This directive makes it
        // a visual calculation.
        allselected( T )
    )
return
    __result

 

Anonymous
Not applicable

roopesh_0-1599041010877.png

Gives me error

Anonymous
Not applicable

You have to be able to say VALUES( T[Year] ). I don't know how you obtain this field from your table but you have to be able to do it for the formula to work.
Anonymous
Not applicable

Yeah... If you start reading the error messages, they will help you diagnose problems.
Anonymous
Not applicable

it says

"The value for 'Year' cannot be determined. Either the column doesn't exist, or there is no current row for this column."

I tried putting the actual year column it worked! thank you.

But I am getting the sum of the columns not the average

 

roopesh_0-1599042017541.png

it should be 58/3(no. of years) for the first group. Please let me know if I am doing anything wrong

 

Anonymous
Not applicable

Mate, you're missing context transition under AVERAGEX. A measure is not the same as putting COUNT(something). A measure is ALWAYS implicitly wrapped in CALCULATE. Since you're not using a measure under AVERAGEX, you have to wrap this expression into CALCULATE yourself.
Anonymous
Not applicable

roopesh_0-1599042352403.png

 

Worked! I learned something new today. Thank you

Anonymous
Not applicable

@Anonymous

Here's a piece of the best advice you can get about PowerBI and DAXing:

As soon as you can, please get yourself the book "The Definitive Guide to DAX" by Marco Russo and Alberto Ferrari and read it as fast as you can. You'll have to read it several times over so start as soon as you can.

This IS simply the best advice you've ever heard/read from a human being about mastering PowerBI, even though you might think at this very moment that I'm out of my mind.

Greg_Deckler
Community Champion
Community Champion

@Anonymous - Perhaps:

Measure = 
  VAR __Group = MAX([sdgStudyGroup])
  VAR __Average = AVERAGEX(FILTER(ALL('Table'),[sdgStudyGroup]=__Group),[Count of vw_AccrualsListPatientID])
RETURN
  __Average


Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

roopesh_0-1599017594663.png

 

It did not work @Greg_Deckler 

 

@Anonymous - Oh, I think I see what is going on, it is a measure aggregation issue. This looks like a measure aggregation problem. See my blog article about that here: https://community.powerbi.com/t5/Community-Blog/Design-Pattern-Groups-and-Super-Groups/ba-p/138149

The pattern is:
MinScoreMeasure = MINX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
MaxScoreMeasure = MAXX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
AvgScoreMeasure = AVERAGEX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
etc.

 

So probably something like:

 

Measure =
  VAR __Group = MAX([sdgStudyGroup])
  VAR __Table = SUMMARIZE(FILTER(ALL('Table'),[sdgStudyGroup] = __Group),[Year],"Count",[vw_AccrualsListPatientID])
RETURN
  AVERAGEX(__Table,[vw_AccrualsListPatientID)

 



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Yes I want to find the average of the [Count of..

@Anonymous - 

Oh, I think I see what is going on, it is a measure aggregation issue. This looks like a measure aggregation problem. See my blog article about that here: https://community.powerbi.com/t5/Community-Blog/Design-Pattern-Groups-and-Super-Groups/ba-p/138149

The pattern is:
MinScoreMeasure = MINX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
MaxScoreMeasure = MAXX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
AvgScoreMeasure = AVERAGEX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
etc.

 

So probably something like:

Measure =
  VAR __Group = MAX([sdgStudyGroup])
  VAR __Table = SUMMARIZE(FILTER(ALL('Table'),[sdgStudyGroup] = __Group),[Year],"Count",COUNT([vw_AccrualsListPatientID]))
RETURN
  AVERAGEX(__Table,[Count])

 

This is why you should always post sample source data because it is hard to tell exactly what things are in images. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

roopesh_0-1599018304211.png

It says i cannot find the name

 

@Anonymous 

Measure =
  VAR __Group = MAX([sdgStudyGroup])
  VAR __Table = SUMMARIZE(FILTER(ALL('Table'),[sdgStudyGroup] = __Group),[Year],"Count",COUNT([vw_AccrualsListPatientID]))
RETURN
  AVERAGEX(__Table,[Count])


Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

roopesh_0-1599018615630.png

 

it gives me all the columns not the filtered one.

 

@Anonymous - Dude, seriously, you need to include more details in your post if you want to get a valid answer.

Measure =
  VAR __Group = MAX([sdgStudyGroup])
  VAR __Table = SUMMARIZE(FILTER(ALLEXCEPT('Table',[Year]),[sdgStudyGroup] = __Group),[Year],"Count",COUNT([vw_AccrualsListPatientID]))
RETURN
  AVERAGEX(__Table,[Count])


Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
amitchandak
Super User
Super User

@Anonymous ,

calculate([AvgSgdGroupMeasure], allexpect(table,Table[SdgStudygroup]))

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

sorry did not work

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.