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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
EVEAdmin
Post Patron
Post Patron

Count Distinct Values By Column and by Date

Hi all

 

I have a table similar to the following

Snag_fdba5a7.png

The table is already link to a DateTable

DBName is the name of the database providing the data

CustomerID is the ID of each customer in that database. 

As there are multiple databases, the customer ID can be repeated. Therefore, if an ID is listed in 2 different databases, it will actually identify 2 different customers.

 

I need to calculate the number of unique customers by year.

 

Hope I am clear, else I can provide more details, thank you.

2 ACCEPTED SOLUTIONS
RakeshNag
New Member

Hi,

 

Please find the below DAX measure solution.

DistinctCountOfCustomer = CALCULATE(DISTINCTCOUNT(DB_Table[CustomerID]),VALUES(Date_Table[Year]))

It is working fine. Please check and advise if it also works as per you.

 

Capture.PNG

 

 

 

Thanks,

Rakesh

View solution in original post

If you need across the used combined column. If you need by DB and By year. Then you can take distinct of customer ID. But if you are using DBname in your visual then the combined one will also work.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

6 REPLIES 6
RakeshNag
New Member

Hi,

 

Please find the below DAX measure solution.

DistinctCountOfCustomer = CALCULATE(DISTINCTCOUNT(DB_Table[CustomerID]),VALUES(Date_Table[Year]))

It is working fine. Please check and advise if it also works as per you.

 

Capture.PNG

 

 

 

Thanks,

Rakesh

@RakeshNag thank you.

That returns unique customers by Year. I need unique customers by DBName by year 

If you need across the used combined column. If you need by DB and By year. Then you can take distinct of customer ID. But if you are using DBname in your visual then the combined one will also work.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
amitchandak
Super User
Super User

Not sure I got it completely.

There can be a few ways. But I will create a combined Column and then take distinct count

 

New column = Table[DBName]& "-"&Table[CustomerID]

Count Customer = calculate(distinctcount(Table[New column]))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak that is simple and should work, thank you.

HOwever, how do I count unique customers by Year?

You can use year filter or datesytd or totalytd. make sure you have date table

example.

 

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(('Date'[Date]),"12/31"))
This Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD((ENDOFYEAR('Date'[Date])),"12/31"))

Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
Last YTD complete Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))
Last to last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-2,Year),"12/31"))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors