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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
abhiram342
Employee
Employee

Optimized way to get Distinct count metric in DAX

Hi All,

 

I have two Fact Tables Table A and Table B. I want to get distinct count metric from Column which is comoon from both tables. Currenlty, I'm using below code and it's taking Time. Please Suggest optimized way for calculating it

 

Example:

FactA[Column] & FactB[Column]:

 

DistinctCount = DISTINCTCOUNT('FactA'[Column])+DISTINCTCOUNT('FactB'[Column])-CALCULATE(DISTINCTCOUNT('FactA'[Column]),TREATAS(VALUES('FactB'[Column]),'FactA'[Column]))

 

 

Thanks,

Abhiram

3 ACCEPTED SOLUTIONS
Greg_Deckler
Super User
Super User

@abhiram342 - Be easier to verify if had sample data or data set but maybe try:

DistinctCount =
  COUNTROWS(
    DISTINCT(
      UNION(
        SELECTCOLUMNS('FactA',"Column",[Column]),
        SELECTCOLUMNS('FactB',"Column",[Column])
      )
    )
  )

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

amitchandak
Super User
Super User

@abhiram342 , Try like

countx(distinct(union(all('FactA'[Column]),all('FactB'[Column]))),[Column])

or

countrows(distinct(union(all('FactA'[Column]),all('FactB'[Column]))))

 

 

View solution in original post

Anonymous
Not applicable

[Distinct Count] =
COUNTROWS(
    DISTINCT(
        UNION(
            VALUES( FactA[Column] ),
            VALUES( FactB[Column] )
        )
    )
)

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

[Distinct Count] =
COUNTROWS(
    DISTINCT(
        UNION(
            VALUES( FactA[Column] ),
            VALUES( FactB[Column] )
        )
    )
)
amitchandak
Super User
Super User

@abhiram342 , Try like

countx(distinct(union(all('FactA'[Column]),all('FactB'[Column]))),[Column])

or

countrows(distinct(union(all('FactA'[Column]),all('FactB'[Column]))))

 

 

Greg_Deckler
Super User
Super User

@abhiram342 - Be easier to verify if had sample data or data set but maybe try:

DistinctCount =
  COUNTROWS(
    DISTINCT(
      UNION(
        SELECTCOLUMNS('FactA',"Column",[Column]),
        SELECTCOLUMNS('FactB',"Column",[Column])
      )
    )
  )

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors