Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hello,
I've got a model like this:
My goal is to count the number of rows in the Projects table that have at least 1 corresponding row in the StaffProj for a given selection of Staff. My attempt was this measure:
Projs With Selected Staff = COUNTROWS(FILTER(
Projects,
COUNTROWS(StaffProj)
))
This measure instead simply yields a count of Projects, regardless of what Staff selection makes. To give an example, first with no filtering (displays 3 correctly):
When filtering on Staff=B, though, it still displays 3 even though it should be 2:
I recognize in this model that I could get this information purely from the StaffProj table, but the actual situation/model is more complex. Why doesn't this approach work and is there an alternate way of getting the correct counts "from" the Projects table?
Solved! Go to Solution.
Hi @kbol ,
You could try the following measure.
Projs With Selected Staff =
CALCULATE (
DISTINCTCOUNT ( 'StaffProj'[Project] ),
ALLSELECTED ( 'Staff'[Name] )
)
Here is the test result.
Hi @kbol ,
You could try the following measure.
Projs With Selected Staff =
CALCULATE (
DISTINCTCOUNT ( 'StaffProj'[Project] ),
ALLSELECTED ( 'Staff'[Name] )
)
Here is the test result.
Hello @v-eachen-msft ,
Thank you, that idea works. I am quite surprised that the FILTER expression on Project in my attempt apparently changes the context such that it discards the filtering from Staff on StaffProj, but using that ALLSELECTED idea addresses that issue with this measure:
Projs With Selected Staff = CALCULATE(
COUNTROWS(Project),
FILTER(
Project,
CALCULATE(COUNTROWS(StaffProj), ALLSELECTED(Staff))
)
)
I've accepted your post as the solution since it is more logical in this scenario. I don't fully understand why we need the ALLSELECTED here, but it does work.
Perhaps a column in Project table like:
Count = COUNTROWS(RELATEDTABLE('StaffProj')
Then you could create a measure:
Project Count = COUNTROWS(FILTER('Projects'),[Count] > 0)
Hi,
I'm afraid that Project column solution doesn't quite work because the filtering on Staff can change and the column is computed at refresh time, including all Staff. Thus with the above data is evaluates to 6 for every project, each having two associated staff.