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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
kbol
Helper I
Helper I

Count on Dim Table Based on Fact Table Filtering

Hello,
I've got a model like this:

model.PNG

 

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):

good.PNG

When filtering on Staff=B, though, it still displays 3 even though it should be 2:

bad.PNG

 

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?

1 ACCEPTED SOLUTION
v-eachen-msft
Community Support
Community Support

Hi @kbol ,

 

You could try the following measure.

Projs With Selected Staff =
CALCULATE (
    DISTINCTCOUNT ( 'StaffProj'[Project] ),
    ALLSELECTED ( 'Staff'[Name] )
)

Here is the test result.

3-2.PNG3-1.PNG 

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

4 REPLIES 4
v-eachen-msft
Community Support
Community Support

Hi @kbol ,

 

You could try the following measure.

Projs With Selected Staff =
CALCULATE (
    DISTINCTCOUNT ( 'StaffProj'[Project] ),
    ALLSELECTED ( 'Staff'[Name] )
)

Here is the test result.

3-2.PNG3-1.PNG 

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

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.

Greg_Deckler
Community Champion
Community Champion

Perhaps a column in Project table like:

 

Count = COUNTROWS(RELATEDTABLE('StaffProj')

 

Then you could create a measure:

 

Project Count = COUNTROWS(FILTER('Projects'),[Count] > 0)



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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. 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors