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
Anonymous
Not applicable

Userelationship on a calculated column with Filter issue

Hi community,

Following is my dataset:

Capture.JPG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

My pbi file:  https://1drv.ms/u/s!Ag919_pO_UKrgQhdlDIIlXqro0QP?e=Jjmbph

Service_attended_date is a calculated column. On a graph I have a measure :

Services attended = CALCULATE(DISTINCTCOUNT('Table'[Client_id]),USERELATIONSHIP('Table'[Service_attended_date],Datedim[Date]),filter('Table','Table'[Case_id] = 'Table'[Service_case_id]))

But this measure results in blank.

Please suggest.

Thanks in advance.

 

 

1 ACCEPTED SOLUTION

 

@Anonymous 

Apologies since I can't check if it works since the sample you provided does not have the fields you want to filter by, but give this a try:

Services attended (more filters) =
VAR CaseID =
    CALCULATETABLE ( 
        VALUES ( 'Table'[Case_id] ), 
         'Table'[Service_code] = "Stage1", 
         'Table'[Service_status] IN { "Closed", "Complete" }
    )
VAR ServiceCaseID =
    CALCULATETABLE (
        VALUES ( 'Table'[Service_case_id] ), 
          'Table'[Service_code] = "Stage1",
          'Table'[Service_status] IN { "Closed", "Complete" }
    )
VAR FiltTable =
    INTERSECT ( CaseID, ServiceCaseID )

RETURN
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Client_id] ),
        USERELATIONSHIP ( 'Table'[Service_attended_date], Datedim[Date] ),
        FiltTable
    )

 

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

7 REPLIES 7
v-kelly-msft
Community Support
Community Support

Hi @Anonymous ,

 

Modify your measure as below:

Services attended = CALCULATE(DISTINCTCOUNT('Table'[Client_id]),filter('Table','Table'[Case_id] = 'Table'[Service_case_id]))

And you will see:

v-kelly-msft_0-1606791142774.png

 

I'm not quite sure why you need to use the relationship to get the distinctcount value,as it can be directly calculated out in its table.

 

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

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

 

Anonymous
Not applicable

@v-kelly-msft  I have to use userelationship as there is already an active relationship between Datedim & my table on a different column.

amitchandak
Super User
Super User

@Anonymous , this one seems to working

Services attended = CALCULATE(CALCULATE(DISTINCTCOUNT('Table'[Client_id]),FILTER('Table','Table'[Case_id] ='Table'[Service_case_id])),USERELATIONSHIP('Table'[Service_attended_date],Datedim[Date]))
Anonymous
Not applicable

@amitchandak  sorry this doesn't work..

PaulDBrown
Community Champion
Community Champion

@Anonymous 

 

Try:

 

Services attended1 =
VAR CaseID =
    VALUES ( 'Table'[Case_id] ) // This creates a table of unique Case_id Values
VAR ServiceCaseID =
    VALUES ( 'Table'[Service_case_id] ) // This creates a table of unique Service_case_id Values
VAR FiltTable =
    INTERSECT ( CaseID, ServiceCaseID ) //Returns a table with rows where Case_id and Service_case_id are the same
RETURN
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Client_id] ),
        USERELATIONSHIP ( 'Table'[Service_attended_date], Datedim[Date] ),
        FiltTable
    )

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

@PaulDBrown thanks, this works!! Can I ask if I want to apply some more filters , how can I do that?

for example : Case_id = service_case_id only for those records where

Service_code ="Stage1" and Service_status  in {"Closed","Comlplete"}

 

@Anonymous 

Apologies since I can't check if it works since the sample you provided does not have the fields you want to filter by, but give this a try:

Services attended (more filters) =
VAR CaseID =
    CALCULATETABLE ( 
        VALUES ( 'Table'[Case_id] ), 
         'Table'[Service_code] = "Stage1", 
         'Table'[Service_status] IN { "Closed", "Complete" }
    )
VAR ServiceCaseID =
    CALCULATETABLE (
        VALUES ( 'Table'[Service_case_id] ), 
          'Table'[Service_code] = "Stage1",
          'Table'[Service_status] IN { "Closed", "Complete" }
    )
VAR FiltTable =
    INTERSECT ( CaseID, ServiceCaseID )

RETURN
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Client_id] ),
        USERELATIONSHIP ( 'Table'[Service_attended_date], Datedim[Date] ),
        FiltTable
    )

 

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






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.