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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
SBR1D
Helper III
Helper III

CountRows problem

Hi Everyone

 

Below is a simplified version of my actual table.

 

I have a slicer where a user can select an Employer name ( A,B,C,D), when they choose an employer I want to get a count of all of the selected IDs in the table.  Here is my current formula..

 

Number of ParentIDs = CALCULATE(COUNTROWS('Learning Plan'),'Learning Plan'[ParentID] =SELECTEDVALUE(Employer[ParentId]),USERELATIONSHIP('Learning Plan'[EmployerId],Employer[EmployerId]))
 
Problem is, if you select Employer A its only counting A's when it should be counting AA's aswell as they have the same ParentEmployerID. 
 
Please help

 

 

EmployerParentEmployerID 
A1 
AA1 
C3 
D4 
AA1 
A1 
AA1 
D4 
DD4 
1 ACCEPTED SOLUTION

The original formula takes into account that you might select more than one value which, in this case, SELECTEDVALUE will not work. If you want just a single selection:

Number of Parent IDs =
VAR __PARENT_ID =
    CALCULATE ( MAX ( 'Table'[ParentEmployerID] ), ALLSELECTED ( 'Table' ) )
RETURN
    CALCULATE (
        COUNTROWS ( 'Learning Plan' ),
        'Learning Plan'[ParentID] = __PARENT_ID,
        USERELATIONSHIP ( 'Learning Plan'[EmployerId], Employer[EmployerId] )
    )

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @SBR1D ,

Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or Accept the helpful suggestions to help others who faced similar requirements.

If these also don't help, please share more detailed information and description to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

danextian
Super User
Super User

Hi @SBR1D 

 

With just the data provided, here's a sample formula:

Number of Parent IDs =
VAR __PARENT_ID =
    SUMMARIZE (
        CALCULATETABLE (
            'Table',
            'Table'[Employer] IN VALUES ( 'Table'[Employer] ),
            REMOVEFILTERS ()
        ),
        'Table'[ParentEmployerID]
    )
RETURN
    CALCULATE (
        COUNTROWS ( 'Learning Plan' ),
        'Learning Plan'[ParentID] IN __PARENT_ID,
        USERELATIONSHIP ( 'Learning Plan'[EmployerId], Employer[EmployerId] )
    )

 

Otherwise, please provide  a sanitized copy of your pbix.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

That looks good but what about the selected value part please?

The original formula takes into account that you might select more than one value which, in this case, SELECTEDVALUE will not work. If you want just a single selection:

Number of Parent IDs =
VAR __PARENT_ID =
    CALCULATE ( MAX ( 'Table'[ParentEmployerID] ), ALLSELECTED ( 'Table' ) )
RETURN
    CALCULATE (
        COUNTROWS ( 'Learning Plan' ),
        'Learning Plan'[ParentID] = __PARENT_ID,
        USERELATIONSHIP ( 'Learning Plan'[EmployerId], Employer[EmployerId] )
    )

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.