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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
DavidNunes7
Helper I
Helper I

How to use distinctcount for multiple columns - DAX

Hello everyone, I need help with Dax syntax and measurements.
I currently have a table with four columns of data, I need a distinct count between the 4 columns
The table is created by dax, i can't even get the columns in the power query 
Sem título.png

Thanks 🙂

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @DavidNunes7 

 

You can try this measure

Measure =
COUNTROWS (
    DISTINCT (
        UNION (
            DISTINCT ( 'Table'[Date1] ),
            DISTINCT ( 'Table'[Date2] ),
            DISTINCT ( 'Table'[Date3] ),
            DISTINCT ( 'Table'[Date4] )
        )
    )
)

vjingzhang_0-1645778366406.png

 

Note that this also counts the blank value. You could substract 1 from it if you don't want to count blank. 

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

10 REPLIES 10
v-jingzhang
Community Support
Community Support

Hi @DavidNunes7 

 

You can try this measure

Measure =
COUNTROWS (
    DISTINCT (
        UNION (
            DISTINCT ( 'Table'[Date1] ),
            DISTINCT ( 'Table'[Date2] ),
            DISTINCT ( 'Table'[Date3] ),
            DISTINCT ( 'Table'[Date4] )
        )
    )
)

vjingzhang_0-1645778366406.png

 

Note that this also counts the blank value. You could substract 1 from it if you don't want to count blank. 

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

I look for the same thing but avoid counting the blank cells.

Hi,

Share some data and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thanks for your help . It's working perfect.

 
DavidNunes7
Helper I
Helper I

Thanks for the answer Just what I want to say is that I would like a different distinction considering as 4 columns.
Some like:

DistintCountCol1 =
DISTINCTCOUNT ( yourTablname[yourColumnName] )AND  ( yourTablname[yourColumnName2] )AND   ( yourTablname[yourColumnName3] )


did you understand?

Thank you for your help
Basically I need the sum of the distinct lines
I have 4 columns with dates. I need to count the total of different days,  considering all these columns

Hi @DavidNunes7 ,

 

If you are targeting to get a single metric in the end which counts distinct values in each of your columns ans adds them up, then you can write the following measure:

Aggregated Distinct Count =
DISTINCTCOUNT ( yourTablname[Column 1] ) +
DISTINCTCOUNT ( yourTablname[Column 2] ) +
DISTINCTCOUNT ( yourTablname[Column 3] ) +
DISTINCTCOUNT ( yourTablname[Column 4] )

 

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

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

Appreciate your Kudos!!

Proud to be a Super User!!

 

I tried this way. However the columns can have the same dates. If I do the distinct count by column and then add up, the number of days will be greater, as it will count repeated days. Maybe some way to aggregate the columns and then count...

 

Sem título.png

 

 

Hi @DavidNunes7 ,

 

When you want distinctCount in a single measure then what it should be?

  • Should it be sum of all distinct counts?
  • Should be a concatenated text value with distinct counts delimited by a delimiter?

I am not sure what you are really trying to achieve here.

 

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

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

Appreciate your Kudos!!

Proud to be a Super User!!

Pragati11
Super User
Super User

Hi @DavidNunes7 ,

 

If you created the above table using DAX then you can't see it in Power Query Editor as it shows only the data that is loaded to Power BI along with any transformations done within the same area.

Anything that is calculated using DAX is something done on top of the Power Query area.

 

To get the distinct count of the column values, you can simply write a DAX measure. For example for one of your columns:

DistintCountCol1 =
DISTINCTCOUNT ( yourTablname[yourColumnName] )

Replace yourTablename and yourColumnName with relevant names in your case.

 

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

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

Appreciate your Kudos!!

Proud to be a Super User!!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.