Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi All,
I have Roster table that has a column of Projects (repeating values) and I need to count how many Projects have been assigned multiple Job Titles.
For Instance:
PROJECT | JOB TITLE |
Alpha | Manager |
Alpha | Member |
Alpha | Member |
Alpha | Tech |
Beta | Manager |
Beta | Tech |
Delta | Manager |
Delta | Member |
Omega | Tech |
I have been able to count how many PROJECTS contain one specific JOB TITLE using
Contains Manager = CALCULATE(DISTINCTCOUNT('Roster'[PROJECT]), FILTER('Roster', [JOB TITLE] = "Manager"))
However, I have not been able to count how many PROJECTS contain, say, "Manager" AND "Tech".
So in this instance I would need "2" to be returned, because only two projects, Alpha and Beta, have both a Manager and Tech assigned.
Thanks!
Solved! Go to Solution.
Hi,
the code:
Measure =
var __Filter = CALCULATETABLE(FILTER('Table';[JOB TITLE] in {"Manager"; "Tech"});ALLEXCEPT('Table';'Table'[PROJECT]))
return
IF(
HASONEVALUE('Table'[PROJECT]);
if(COUNTROWS(__Filter)>=2;1;0);
COUNTROWS(
FILTER(
CALCULATETABLE(SUMMARIZE(__Filter;'Table'[PROJECT];"c"; DISTINCTCOUNT('Table'[JOB TITLE])));[c]>=2
)
)
)
As seen here:
File.
Pls marks as solution if this works for you. Thumbs up for the effort would be great.
Kind regards, Steve.
Proud to be a Super User!
Awesome Keyboard Shortcusts in Power BI, thumbs up if you like the article
My Community Blog Articles (check them out!)
My Blog - Power M code to automatically detect column types -
How to create test data using DAX!
Please try this expression in your measure. It returns 2 for your example data. Replace ProjectRoles with the name of your actual table.
Projects with Manager and Tech =
COUNTROWS (
FILTER (
DISTINCT ( ProjectRoles[PROJECT] ),
CALCULATE (
DISTINCTCOUNT ( ProjectRoles[JOB TITLE] ),
ProjectRoles[JOB TITLE] IN { "Manager", "Tech" }
) = 2
)
)
If this works for you, please mark it as the solution. Kudos are appreciated too. Please let me know if not.
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
Hi,
the code:
Measure =
var __Filter = CALCULATETABLE(FILTER('Table';[JOB TITLE] in {"Manager"; "Tech"});ALLEXCEPT('Table';'Table'[PROJECT]))
return
IF(
HASONEVALUE('Table'[PROJECT]);
if(COUNTROWS(__Filter)>=2;1;0);
COUNTROWS(
FILTER(
CALCULATETABLE(SUMMARIZE(__Filter;'Table'[PROJECT];"c"; DISTINCTCOUNT('Table'[JOB TITLE])));[c]>=2
)
)
)
As seen here:
File.
Pls marks as solution if this works for you. Thumbs up for the effort would be great.
Kind regards, Steve.
Proud to be a Super User!
Awesome Keyboard Shortcusts in Power BI, thumbs up if you like the article
My Community Blog Articles (check them out!)
My Blog - Power M code to automatically detect column types -
How to create test data using DAX!
Other than a few syntax issues (maybe I have an older version or something) this worked perfectly, thank you!
Something like this?
Manger & Tech =
VAR Result =
CALCULATE (
DISTINCTCOUNT ( Michael[Job Title] ),
FILTER (
ALL ( Michael[Job Title] ),
Michael[Job Title] IN { "Manager", "Tech" }
)
)
RETURN
IF ( HASONEVALUE ( Michael[Project] ), Result, BLANK () )
You can also use less verbose version.
Manger & Tech =
VAR Result =
CALCULATE (
DISTINCTCOUNT ( Michael[Job Title] ),
Michael[Job Title] IN { "Manager", "Tech" }
)
RETURN
IF ( HASONEVALUE ( Michael[Project] ), Result, BLANK () )
Not quite. It looks like your code returns how many Managers and/or Techs are assigned to each project.
I need my code to return how many projects have a Manager and Tech assigned to them, so I can put it on a card.
So in this instance I would need "2" to be returned, because only two projects, Alpha and Beta, have both a Manager and Tech assigned.
is this how you want it?
User | Count |
---|---|
22 | |
11 | |
8 | |
6 | |
6 |
User | Count |
---|---|
25 | |
13 | |
11 | |
9 | |
6 |