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

Min Max and average with count in dax

Hi 

I am struggling with min max and avg in Power BI using DAX.

I have the following table.

 Student        Subject
st1                  math

st1                  eng

st1                  phy

st2                  phy

st2                  math

st2                  eng

st2                  bio

st2                  che

st2                  comp

st3                  eng

st3                  math

st1                  comp

st3                  comp

st2                  history

 

I want to cont subjects by each student and then I want to apply min max and avg on students.

Let say

Student  SubjectCount

st1           4

st2           7

st3           3

 

My desired results should be

Max_student_subject
st2 = 7
Min_student subject

st3 = 3

 

Thanks in Advance

1 ACCEPTED SOLUTION
v-yulgu-msft
Employee
Employee

Hi @Anonymous,

 

Please refer to below measures:

count sub = COUNT(Data[Subject]) 

Min = RANKX(ALLSELECTED(Data[Student]),[count sub],,ASC,Dense)
Max = RANKX(ALLSELECTED(Data[Student]),[count sub],,DESC,Dense)
average = AVERAGEX(ALLSELECTED(Data),[count sub])

You need two table visuals and a card visual to display each Min, Max and Average value. You should apply visual level filters to table visuals.

1.PNG2.PNG

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
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
v-yulgu-msft
Employee
Employee

Hi @Anonymous,

 

Please refer to below measures:

count sub = COUNT(Data[Subject]) 

Min = RANKX(ALLSELECTED(Data[Student]),[count sub],,ASC,Dense)
Max = RANKX(ALLSELECTED(Data[Student]),[count sub],,DESC,Dense)
average = AVERAGEX(ALLSELECTED(Data),[count sub])

You need two table visuals and a card visual to display each Min, Max and Average value. You should apply visual level filters to table visuals.

1.PNG2.PNG

Best regards,

Yuliana Gu

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

Hi v_yulgu-msft,

 

thanks for your reply.

Your solution is working fine but I have one issue regarding slicer filtering. If I use "ALLSELECTED" then my slicer filters are not working any more regarding this calculation.

Can you please help me regarding this.

 

Regards,

Asif

MFelix
Super User
Super User

Hi  @Anonymous,

 

Create the following measures:

Count Students = COUNT(Students[Student ])

Max students = MAXX(ALLSELECTED(Students[Student ]);[Count Students])

Min students = MINX(ALLSELECTED(Students[Student ]);[Count Students])

Average students = AVERAGEX(ALLSELECTED(Students[Student ]);[Count Students])

Be aware that this is making the selection of the selected students, if you want that your measure to be overall the full dataset no matter the selection of students change the ALLSELECTED to ALL.

 

Regards,

MFelix


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Hi MFelix,

thanks for your reply.

 

I have applied your method and I am getting these rows back.

png.PNG

But I want single row e.g

st3 = 3

 

Regards,

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.