Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hi,
I have two tables that follow this structure:
Table: Employee
ID | Name |
1 | John |
2 | Jack |
3 | Bob |
Table: Feedback
ID | Name |
1 | John |
1 | John |
2 | Jack |
2 | Jack |
2 | Jack |
3 | Bob |
I want to know the number of feedbacks (number of rows in the feedback table) for each person (ID), but I want 4 different measures:
1st measure: count of occurrences of IDs in table Feedback that appear at least 1 time.
2nd measure: count of occurrences of IDs in table Feedback that appear at least 1 or 2 times.
3rd measure: count of occurrences of IDs in the Feedback table that appear at least 1, 2 or 3 times.
4th measure: count of occurrences of IDs in the Feedback table that appear at least 1, 2, 3 or 4 times.
So based on the example tables above:
1st measure = 3 (Jhon, Jack and Bob)
2nd measure = 2 (Jhon and Jack)
3nd measure = 1 (Jack)
4nd measure = 0
Can someone help me?
Solved! Go to Solution.
Hi @req77
Try this...
FeedbackCount = COUNT(Feedback[Name])
Measure XX =
VAR EmployeeSummary =
ADDCOLUMNS(
Employee,
"FeedbackCount",
FeedbackCount
)
RETURN
COUNTROWS(
FILTER(
EmployeeSummary,
FeedbackCount > XX
)
)
In the second measure (named Measure XX) substitute XX with the count you want to filter for. Hope this helps!
Similar solution to @littlemojopuppy (started playing when it came in).
Main difference is no need to build the summary table. Won't make any difference on small datasets but should work faster if you have large amounts of data.
2+ Feedback =
COUNTROWS (
FILTER (
VALUES ( Employee[ID] ),
CALCULATE ( COUNTROWS ( Feedback ) ) >= 2
)
)
You could also add a disconnected parameter table with numbers from 1 to n which the measure could read so you don't need multiple versions of the code:
Employees With Feedback =
VAR SelectedNumber = SELECTEDVALUE ( Parameter[Number] )
VAR Result =
COUNTROWS (
FILTER (
VALUES ( Employee[ID] ),
CALCULATE ( COUNTROWS ( Feedback ) ) >= SelectedNumber
)
)
RETURN Result
Excel worksheet formula is powerful enough to resolve such a simple quesiton,
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
Similar solution to @littlemojopuppy (started playing when it came in).
Main difference is no need to build the summary table. Won't make any difference on small datasets but should work faster if you have large amounts of data.
2+ Feedback =
COUNTROWS (
FILTER (
VALUES ( Employee[ID] ),
CALCULATE ( COUNTROWS ( Feedback ) ) >= 2
)
)
You could also add a disconnected parameter table with numbers from 1 to n which the measure could read so you don't need multiple versions of the code:
Employees With Feedback =
VAR SelectedNumber = SELECTEDVALUE ( Parameter[Number] )
VAR Result =
COUNTROWS (
FILTER (
VALUES ( Employee[ID] ),
CALCULATE ( COUNTROWS ( Feedback ) ) >= SelectedNumber
)
)
RETURN Result
@bcdobbs you're right...I've totally gotten into this habit of creating summary tables. I need to get out of that... 😉
Hi @req77
Try this...
FeedbackCount = COUNT(Feedback[Name])
Measure XX =
VAR EmployeeSummary =
ADDCOLUMNS(
Employee,
"FeedbackCount",
FeedbackCount
)
RETURN
COUNTROWS(
FILTER(
EmployeeSummary,
FeedbackCount > XX
)
)
In the second measure (named Measure XX) substitute XX with the count you want to filter for. Hope this helps!
User | Count |
---|---|
98 | |
91 | |
84 | |
72 | |
67 |
User | Count |
---|---|
114 | |
103 | |
100 | |
72 | |
64 |