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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
rdnguyen
Helper V
Helper V

Count rows per category in slicer

Hi All,

I have the following relationship model and was trying to count how many Job per Workcenter. My calculation as below failed to bring up any number and my coffee didn't really help me much 😉

 

Kindly help me understand what I am missing here? Especially what if I want to count if the relationship is not established (inactive one)?

rdnguyen_0-1657114766157.png

 

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

If there is an inactive relationship then you could do something like

c_HideEmpty =
SUMX (
    'DIM-WorkCenter',
    COUNTROWS (
        CALCULATETABLE (
            RELATEDTABLE ( 'Job-WCRef_job' ),
            USERELATIONSHIP ( 'DIM-WorkCenter'[Column 1], 'Job-WCRef_job'[Column 2] )
        )
    )
)

If there is no relationship at all then you could use TREATAS, something like

c_HideEmpty =
SUMX (
    'DIM-WorkCenter',
    COUNTROWS (
        CALCULATETABLE (
            'Job-WCRef_job',
            TREATAS ( { 'DIM-WorkCenter'[Column 1] }, 'Job-WCRef_job'[Column 2] )
        )
    )
)

View solution in original post

5 REPLIES 5
rdnguyen
Helper V
Helper V

I think I found the answer for myself. I created all relationship possible from Dim to Fac (1 active and 2 none), then apply this measure calculation:

 

m_HideEmpty =
CALCULATE(COUNTROWS('Job-WCRef_job'),USERELATIONSHIP('DIM-WorkCenter'[c_sitewcID],'Job-WCRef_job'[h_sitewcID-current]))
johnt75
Super User
Super User

If there is an inactive relationship then you could do something like

c_HideEmpty =
SUMX (
    'DIM-WorkCenter',
    COUNTROWS (
        CALCULATETABLE (
            RELATEDTABLE ( 'Job-WCRef_job' ),
            USERELATIONSHIP ( 'DIM-WorkCenter'[Column 1], 'Job-WCRef_job'[Column 2] )
        )
    )
)

If there is no relationship at all then you could use TREATAS, something like

c_HideEmpty =
SUMX (
    'DIM-WorkCenter',
    COUNTROWS (
        CALCULATETABLE (
            'Job-WCRef_job',
            TREATAS ( { 'DIM-WorkCenter'[Column 1] }, 'Job-WCRef_job'[Column 2] )
        )
    )
)
rdnguyen
Helper V
Helper V

@johnt75 what about if there is no relationship or inactive relationship? As I have 3 foreign keys in fact table mapping to the same Dimension?

johnt75
Super User
Super User

Try

c_HideEmpty = SUMX( 'DIM-WorkCenter', COUNTROWS(RELATEDTABLE('Job-WCRef_job')))

This would count total, not every single category. Your later reply was absolutely useful. I found one for me, then notice your reply was far better. Kudo to you and thanks alot for your help!!!!

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.