cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

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

Accepted Solutions
Highlighted
Microsoft
Microsoft

Re: Min Max and average with count in dax

Hi @asif,

 

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
Highlighted
Super User III
Super User III

Re: Min Max and average with count in dax

Hi  @asif,

 

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





Highlighted
Frequent Visitor

Re: Min Max and average with count in dax

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,

Highlighted
Microsoft
Microsoft

Re: Min Max and average with count in dax

Hi @asif,

 

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

Highlighted
Frequent Visitor

Re: Min Max and average with count in dax

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

Helpful resources

Announcements
Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Using the Community

Using the Community

Need help with the Power BI Community? Our 'Using the Community' support articles are a great place to start.

Galleries

Galleries

Looking for inspiration on how to present your data? Need instructional videos? Check out our Galleries!

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors