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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ronaldbalza2023
Continued Contributor
Continued Contributor

Count of Total Customers by Tasks

Hi everyone, I was puzzle how to count the total number of customers by Tasks by the given below scenario. Thanks in advance

Two tables have the inactive relationships: Tasks[Jobs Job Client ID] and Clients[ID]

DAX Measure

Total Customers by Tasks = 
CALCULATE (
    DISTINCTCOUNT ( Clients[ID] ),
    FILTER ( Clients, Clients[Is Prospect] = "No" ),
    USERELATIONSHIP ( Clients[ID], Tasks[Jobs Job Client ID] )
)

ronaldbalza2023_1-1663121545192.png

 

 

1 ACCEPTED SOLUTION
TomMartens
Super User
Super User

Hey @ronaldbalza2023 ,

 

I do not understand your question because I do not see the problem.

 

Nevertheless, I would write the measure like this

 

 

Total Customers by Tasks = 
CALCULATE (
    DISTINCTCOUNT ( Clients[ID] ),
    Clients[Is Prospect] = "No",
    USERELATIONSHIP ( Clients[ID], Tasks[Jobs Job Client ID] ),
    CROSSFILTER( Clients[ID], Tasks[Jobs Job Client ID], BOTH )
)

 

 

Referencing only the column [Is Prospect] as a filter is more efficient than using the function FILTER (reading the complete table, all the columns), as the vertipaq engine does not need to read the whole table.

See CROSSFILTER here: CROSSFILTER – DAX Guide
CROSSFLTER is necessary as you want the column on the many-side of the relationship filtering the table of the one-side (at least this is my understanding of the problem you are trying to solve.

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

4 REPLIES 4
TomMartens
Super User
Super User

Hey @ronaldbalza2023 ,

 

I do not understand your question because I do not see the problem.

 

Nevertheless, I would write the measure like this

 

 

Total Customers by Tasks = 
CALCULATE (
    DISTINCTCOUNT ( Clients[ID] ),
    Clients[Is Prospect] = "No",
    USERELATIONSHIP ( Clients[ID], Tasks[Jobs Job Client ID] ),
    CROSSFILTER( Clients[ID], Tasks[Jobs Job Client ID], BOTH )
)

 

 

Referencing only the column [Is Prospect] as a filter is more efficient than using the function FILTER (reading the complete table, all the columns), as the vertipaq engine does not need to read the whole table.

See CROSSFILTER here: CROSSFILTER – DAX Guide
CROSSFLTER is necessary as you want the column on the many-side of the relationship filtering the table of the one-side (at least this is my understanding of the problem you are trying to solve.

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Hi @TomMartens, thanks for taking the time on this. It is the crossfilter function that I am looking for. As you can see on the snapshot table, it only aggregates the data and is not segregated the total number of customers by tasks. Thanks and appreciated it 🙂

Hey @ronaldbalza2023 ,

 

please let me know if the CROSSFILTER function provides what you are looking for.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

It is @TomMartens ...I am looking for a ways to optimize the dax 🙂 Thanks again for your help.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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