cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
tanat_inc
Helper I
Helper I

Distinct count of two column with summarize does not work with userelationship()

Hi community, 

I use DAX code and relation ship below to try to distinctcount by HN and Date. The calculation work well if I have active relationship between  d_date_table[Date]  and  f_visit_info[Date].

Problem is : When I switch relationship between  d_date_table[Date]  and  f_visit_info[Date] to inactive and use userelationship() as the code below, it's does not work.

Campus Visit =
  VAR _table = SUMMARIZE('f_visit_info','f_visit_info'[visit_date],"distinctcount",DISTINCTCOUNTNOBLANK('f_visit_info'[hn]))
RETURN  CALCULATE(
  SUMX(_table,[distinctcount]),
  USERELATIONSHIP('d_date_table'[Date],f_visit_info[visit_date])
)

tanat_inc_0-1620788272033.png

 

When relationship is intactive, result is as below : 

tanat_inc_1-1620788357210.png

While the same code with active relationship provides the right result as below : 

tanat_inc_2-1620788419940.pngtanat_inc_4-1620788490705.png

 

How should I rewrite the code to be able to inactivate relation and use "userelationship()" fuction in measure instrad.

 

1 ACCEPTED SOLUTION
amitchandak
Super User IV
Super User IV

@tanat_inc , Try a measure like

 

Campus Visit =
VAR _table = SUMMARIZE('f_visit_info','f_visit_info'[visit_date],"distinctcount",calculate(DISTINCTCOUNTNOBLANK('f_visit_info'[hn]),
USERELATIONSHIP('d_date_table'[Date],f_visit_info[visit_date])))
RETURN CALCULATE(
SUMX(_table,[distinctcount])
)



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

View solution in original post

4 REPLIES 4
amitchandak
Super User IV
Super User IV

@tanat_inc , Try a measure like

 

Campus Visit =
VAR _table = SUMMARIZE('f_visit_info','f_visit_info'[visit_date],"distinctcount",calculate(DISTINCTCOUNTNOBLANK('f_visit_info'[hn]),
USERELATIONSHIP('d_date_table'[Date],f_visit_info[visit_date])))
RETURN CALCULATE(
SUMX(_table,[distinctcount])
)



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

View solution in original post

It's work !!!

You solved 3 of my issues already in this month. 
That's really save my day.

Thank you very much 🙂 🙂

Krutigawale33
Responsive Resident
Responsive Resident

Hello @tanat_inc ,

 

You can with lookupvalue

 

Please find the more information on the below link

https://dax.guide/lookupvalue/

Thanks friend, this should be a useful alternative work around.

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

July 2021 Update 768x460.png

Check it out!

Click here to read more about the July 2021 Updates

Top Solution Authors
Top Kudoed Authors