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
arb1782
Helper III
Helper III

Dax for average group size measure

Hi

 

I've just modelled some data so that I have each row is an individual who has attending a health group. I want to create a measure that shows the average number of group participants.

 

My data is structured like this:

 

Group IDDate of groupGroup namePerson ID
1

12/09/20

Health groupA
1

12/09/20

Health groupB
1

12/09/20

Health groupC
213/09/20Disability groupD
213/09/20Disability groupE
314/09/20Exercise groupA
314/09/20Exercise groupC
314/09/20Exercise groupG
314/09/20Exercise groupH

 

What would be the DAX for this?

 

Thanks

arb

1 ACCEPTED SOLUTION

Hi,

Try this measure

=countrows(Data)/distinctcount(Data[Group ID])

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

10 REPLIES 10
amitchandak
Super User
Super User

@arb1782 , Try like


AvergaeX(Values(Table[Group ID]), count(Table[Person ID]))

or

AvergaeX(summarize(Table[Group ID],"_1", count(Table[Person ID])),[_1])

Hi

 

The answer from the sample data should be 3. So far the table and the two formulae provided don't solve my issue.

 

Thanks for responses so far.

Hi,

Try this measure

=countrows(Data)/distinctcount(Data[Group ID])

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thanks all

Any other ideas @amitchandak  @VijayP  @negi007  ?

Hi @arb1782 ,

You can create a measure as below:

Measure =
VAR _countofallp =
    CALCULATE ( COUNT ( 'Table'[Person ID] ), ALL ( 'Table' ) )
VAR _countofgroup =
    CALCULATE ( DISTINCTCOUNT ( 'Table'[Group ID] ) )
RETURN
    DIVIDE ( _countofallp, _countofgroup, 0 )​​​

Best Regards

Rena

 

 

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

Thanks @v-yiruan-msft 

 

I get the following error: "The following syntax error occurred during parsing: Invalid token, Line 7, Offset 46, ." The little red squiggle is after the final bracket of the DIVIDE.

 

Any idea how to resolve this?

Hi @arb1782 ,

Sorry, I made a mistake... The error message is caused by the wrong use of the last bracket in the formula, please update the formula of measure as below:

Measure =
VAR _countofallp =
CALCULATE ( COUNT ( 'Table'[Person ID] ), ALL ( 'Table' ) )
VAR _countofgroup =
CALCULATE ( DISTINCTCOUNT ( 'Table'[Group ID] ) )
RETURN
DIVIDE ( _countofallp, _countofgroup, 0 )

In addition, you can use DAX Formatter tool to check if there are any syntax errors in your formula and format it.

Best Regards

Rena

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

@arb1782 

Do you want to have this as a result?

2020-09-21_211727.png




Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
MY Blog || My YouTube Channel || Connect with me on Linkedin || My Latest Data Story - Ageing Analysis

Proud to be a Super User!


negi007
Community Champion
Community Champion

@arb1782 If you only wish to calculate the number of participant per group, there is no need to create a measure. it can be done simply using below approach. Put person ID in the values field and change the calculation to count from the dropdown icon

 

negi007_0-1600702856355.png

 




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



Proud to be a Super User!


Follow me on linkedin

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.