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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
jharsh
Frequent Visitor

Count Rows In Table Default to 0 Returning to Many Results

I am trying to count the number of rows in a left join table defaulting to zero if there are none.  When I do this the other table filters are no longer applied and I get all the records in the count table back.

 

Example

 

Managers                  Offices                              SalesPeople                        Customers

____________________________________________________________________________________________________
Manager          Manager   Office              SalesPerson  Office            SalesPerson Customer

Bob                   Bob              1                   Tom                 1                 Tom             Joe 

Matt       1----* Matt             2     1-----*   Harry               1     1---*    Harry           Jane

                                                                  Frank               1                 Harry           George                                                                                                                                        Greg                2                

 

 

Expected Results when Manager is selected from slicer 

SalesPerson    Customer Count

Tom                 1

Harry               2

Frank               0

 

Actual Results

SalesPerson Customer Count

Tom              1

Harry            2

Frank            0

Greg             0

 

I am doing a measure from the Manager table 
CustomerCount = IF(ISBLANK(COUNT(Customers[Customer])),0,COUNT(Customers[Customer]))  but this is giving me all sales person not just the ones in the office for the manager selected.

 

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

Hi @jharsh ,

I modify the formula, and it works fine now.

Show Sales Person in Table = 
var selectedManager = SELECTEDVALUE(Managers[Manager])
var currentOffice = SELECTEDVALUE(SalesPeople[Office])
var employeesManager = LOOKUPVALUE( Offices[Manager], Offices[Office], currentOffice )
return IF( employeesManager = selectedManager||NOT(ISFILTERED('Managers'[Manager])), 1 )

vkalyjmsft_0-1646206329974.png

vkalyjmsft_1-1646206349099.png

vkalyjmsft_2-1646206371224.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

5 REPLIES 5
v-yanjiang-msft
Community Support
Community Support

Hi @jharsh ,

I modify the formula, and it works fine now.

Show Sales Person in Table = 
var selectedManager = SELECTEDVALUE(Managers[Manager])
var currentOffice = SELECTEDVALUE(SalesPeople[Office])
var employeesManager = LOOKUPVALUE( Offices[Manager], Offices[Office], currentOffice )
return IF( employeesManager = selectedManager||NOT(ISFILTERED('Managers'[Manager])), 1 )

vkalyjmsft_0-1646206329974.png

vkalyjmsft_1-1646206349099.png

vkalyjmsft_2-1646206371224.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

johnt75
Super User
Super User

The issue is the COALESCE. By returning 0 instead of BLANK each row has a value, and so each row is returned. But removing the COALESCE and returning BLANK instead means that not all employees are returned, only the ones with at least one customer, so Greg doesn't show up. 

You can get around this by removing the COALESCE from the measure so that it returns BLANK instead of 0, then creating a new measure

Show Sales Person in Table = 
var selectedManager = SELECTEDVALUE(Managers[Manager])
var currentOffice = SELECTEDVALUE(SalesPeople[Office])
var employeesManager = LOOKUPVALUE( Offices[Manager], Offices[Office], currentOffice )
return IF( employeesManager = selectedManager, 1 )

Then making some tweaks to your visuals. Firstly, on the visual showing the sales person and the count of customers, make sure that you're using the SalesPeople[SalesPerson] column and not the Customers[SalesPerson]. Then choose the SalesPerson field in the Values well, click the down arrow and choose "Show items with no data".

Next add the new measure you created as a filter on this visual, only show items when value is 1.

That should give you what you're after.

This works for only showing the SalesPerson records for the manager. I can add the count of Customers without getting the unwanted customers as well. The only issue is the count is empty instead of 0 if the SalesPerson has no customers.

 

This also doesn't work when no Manager is selected in the slicer to see all results.

johnt75
Super User
Super User

I think the below should work

CustomerCount = COALESCE( CALCULATE( COUNTROWS( Customers ) ), 0 )

The CALCULATE introduces context transition so should pick up the filter on manager

Thanks for the feedback.  Unfortunately, that formula still returns all results from the Customer table instead of the filtered by Manager results.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.