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

DISTINCT COUNT with CROSSJOIN

Hello, 

 

I don't have much knowledge of DAX, I made a query with CROSSJOIN, except that as there are duplicate values in the output count, I would like to have unique values. Here is my query:

 

var NumberAccountsWithAppointements=
FILTER(CROSSJOIN(
                  accounts,SELECTCOLUMNS(appointements,"appointement_account_id",appointments[_regardingobjectid_value])
          ), [accountid]=[appointement_account_id] 
)  RETURN COUNTROWS(NumberAccountsWithAppointements)
 
As there are multiples rows in appointements table, an account is counted 2 times. 
How can I change this request so that I have distinct count for accounts. 
 
I Need assistance ASAP.
 
Thank you. 
 
 
2 ACCEPTED SOLUTIONS

Hi,
Have a look at this Example

 

Think you were over complicating it with cross join etc rather than using the exisitng relationships.

 

Using your data...

 

bcdobbs_0-1641647921591.png

 

bcdobbs_1-1641647948192.png

Customers With An Appointment = 
    DISTINCTCOUNT ( Appointment[CustomerId] )

 

 



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

View solution in original post

Anonymous
Not applicable

Thank you very much for your held. Indeed DISTINCTCOUNT solve the issue. 

As well I found that I could have juste add a SUMMARIZE in the COUNTROWS : 

RETURN COUNTROWS(SUMMARIZE(NumberAccountsWithAppointements,[accountid])). 

 

Thanks very much for your help

View solution in original post

7 REPLIES 7
smpa01
Super User
Super User

@Anonymous  provide sample data/sample pbix

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Anonymous
Not applicable

@smpa01  I make it very simple so that you get my issue.  This is the result I want. I need a DAX request for thatThis is the result I want. I need a DAX request for that

Anonymous
Not applicable

@amitchandak Here is the full request in DAX : 

 

_NumberAppointementsForUser =
var filteredAccounts = FILTER(accounts, Query[AccountOwnerIdCheck]=1 && accounts[statecode]=0 && accounts[ed_typedefamille]=1)
var filteredAppointements = FILTER(appointments,Query[AppointementOwnerIdCheck]=1)

var nbrdv=
FILTER(CROSSJOIN(filteredAccounts,SELECTCOLUMNS(filteredAppointements,"appointement_account_id",appointments[_regardingobjectid_value])), [accountid]=[appointement_account_id])
 
RETURN IF(COUNTROWS(nbrdv)=0,CONCATENATE("# ",0), CONCATENATE("# ",COUNTROWS(nbrdv)))
amitchandak
Super User
Super User

@Anonymous ,If this does not help
Can you share sample data and sample output in table format?

Anonymous
Not applicable

@amitchandak See what I want to do. Can I have the DAX request for this case pleaseCan I have the DAX request for this case please

Hi,
Have a look at this Example

 

Think you were over complicating it with cross join etc rather than using the exisitng relationships.

 

Using your data...

 

bcdobbs_0-1641647921591.png

 

bcdobbs_1-1641647948192.png

Customers With An Appointment = 
    DISTINCTCOUNT ( Appointment[CustomerId] )

 

 



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!
Anonymous
Not applicable

Thank you very much for your held. Indeed DISTINCTCOUNT solve the issue. 

As well I found that I could have juste add a SUMMARIZE in the COUNTROWS : 

RETURN COUNTROWS(SUMMARIZE(NumberAccountsWithAppointements,[accountid])). 

 

Thanks very much 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.