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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Jit007
Helper I
Helper I

Count of employee per Average score Category

Trying to figure out how to use DAX query to count emp id per average score category

Expected Result require in visual 

how many analyst per score category

Avg score

0 to 74 ?

74 to 84 ?

85 to 100 ?

 

sample data

emp id  score

AA       95

AA       75

BB       85

BB      100

CC       45

CC      85 

1 ACCEPTED SOLUTION

Revised PBI file attached.

Hope this helps.

Ashish_Mathur_0-1711166560260.png

 


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

View solution in original post

13 REPLIES 13
dufoq3
Super User
Super User

Hi @Jit007, don't be impatient 😉

You can do it also in power query.

 

Result

dufoq3_0-1711141711469.png

 

Replace code for AvgScoreTable and DataTable steps with your table references

let
    AvgScoreTable = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlDSUTI3VYrViQZROkoWELYFiG1oYKAUGwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [From = _t, To = _t]),
    ChangedTypeAvgScore = Table.TransformColumnTypes(AvgScoreTable,{{"From", Int64.Type}, {"To", Int64.Type}}),
    Ad_ScoreText = Table.AddColumn(ChangedTypeAvgScore, "Score Text", each Text.From([From]) & " to " & (if [To] = 100 then "100" else Text.From([To]-1)), type text),
    DataTable = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRU0lGyNFWK1YGyzSFsJycg2wKJbWhgAOY4OwM5JqYINkhRLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"emp id" = _t, score = _t]),
    ChangedTypeDataTable = Table.TransformColumnTypes(DataTable,{{"score", type number}}),
    Ad_AvgScore = Table.AddColumn(ChangedTypeDataTable, "Avg Score", each Table.SelectRows(Ad_ScoreText, (x)=> ([score] >= x[From] and [score] < x[To]))[Score Text]{0}? ?? Table.Last(Ad_ScoreText)[Score Text], type text)
in
    Ad_AvgScore

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Thank you for your reply.

sorry if i confused you

I want expected result as below via measure

 

avg score category   emp.count

0-74 -                       10 emps

75 to 84 -                  20 emps

85 to 100 -                 5 emps

 

Hi,

PBI file attached.

Hope this helps.

Ashish_Mathur_0-1711163350337.png

 


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

Thanks,,but still its not matching

Data showing for 5 emps in category & total count showing 3 emp.. please help to fix this 

You are welcome.  That answer is correct.  Look at your own data carefully - one Emp ID falls in multiple categories.


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

Yes i wanted to fix this with Avg Score category by calcuting multiple score of that emps

Jit007_0-1711166174538.png

 

 
Result
categories emps
0 to 74    1
75 to 84    1
85 to 100   1
Total        3 emps

 

Revised PBI file attached.

Hope this helps.

Ashish_Mathur_0-1711166560260.png

 


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

@Ashish_Mathur  Thanks Ashish..

You are welcome.


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

I do not understand your requirement at all.  Based on the data that you have shared, show the expected result very clearly.


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

This is whati am looking for 

Jit007_0-1711166373972.png

 

Jit007
Helper I
Helper I

@Ashish_Mathur Please help.. Thanks

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

Top Solution Authors
Top Kudoed Authors