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
sureddy1
New Member

dax group by measure

I have a table over which i need to calculate average of a column grouped by multiple columns. I am able to create a table using below: 

 

GROUPBY(tableA,tableA[groupbyA],tableA[groupbyB],"AvgColumn",AVERAGEX(CURRENTGROUP(), tableA[Column-on-which-i-need-average]))

 

But this table gives me a calculated column for "AvgColumn". When i use this table in dashboard, i am forced to choose an aggregation or formula which i do not need. I need a measure instead which can be used without further aggregation when showing on Power BI Dashboard. 

 

How can i achieve this?. Is this even possible?.

1 ACCEPTED SOLUTION
v-qiuyu-msft
Community Support
Community Support

Hi @sureddy1,

 

You can create a measure like below:

 

Measure = CALCULATE(AVERAGE(Table1[Amount]),FILTER(ALLSELECTED('Table1'),'Table1'[Group]=MAX('Table1'[Group]) && 'Table1'[Year]=MAX('Table1'[Year])))

 

q5.PNG

 

You can download attached .pbix file to have a look.

 

Best Regards,
Qiuyun Yu

 

 

Community Support Team _ Qiuyun Yu
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

4 REPLIES 4
abhiiimr15
Frequent Visitor

On Similar lines, i need to calculate the avg. score. 

 

SurveyIDParameterSubParameterQuestionScoreScoreatSubParameterlevel     
111Q12.671.8     
111Q211.8     
When I do avg. of Score on Power BI Chart then avg score on Power BI shows 1.5 and not 1.8. Not sure why  

 

Please could any one help on the above scenario. Why does Power BI calculate the wrong avg. for SubParameter=1 . 

v-qiuyu-msft
Community Support
Community Support

Hi @sureddy1,

 

You can create a measure like below:

 

Measure = CALCULATE(AVERAGE(Table1[Amount]),FILTER(ALLSELECTED('Table1'),'Table1'[Group]=MAX('Table1'[Group]) && 'Table1'[Year]=MAX('Table1'[Year])))

 

q5.PNG

 

You can download attached .pbix file to have a look.

 

Best Regards,
Qiuyun Yu

 

 

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

Hello,

I am trying to do something similar but can't follow the solution to apply it to my case. 

 

I have a table of patients and clinical results (Blood pressure):

patientid      date      value,   program status (indicates if enrolled in a specific health program)
1                 1/1/18    87        inactive
1                 2/1/18    80        active

 

I need to have a flag on each PATIENTT to indicate if the patient is active at any point during a daterange I select from a slicer. If there is even one record for the patient that has "program status" =  active during the slicer range, all rows of the patient should be flagged as true. If none of the records are showing "active" for the slicer range, all rows should be false. 

 

If I choose 1/1/18 - 1/15/18, I need to see:

patientid      date      value,   program status  ActiveInDateRange (this indicates the patient is not active during the time selected regardless if there are some rows of the patient showing active )
1                 1/1/18    87        inactive                    false
1                 2/1/18    80        active                       false

 

If I choose 1/1/18 - 3/1/18 I should see:
patientid      date      value,   program status  ActiveInDateRange (this indicates the patient IS  active during the time selected regardless if threre are specific rows of the patient showing inactive )
1                 1/1/18    87        inactive                    true
1                 2/1/18    80        active                       true

Essentially i'm trying to say "find all rows of the patient (group by patient) where program status = true and if count > 0 then the new measure should be "true", otherwise "false". 

Can you help me create this measure? 

Thank You @v-qiuyu-msft. This worked perfectly.

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.