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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
ClemFandango
Advocate II
Advocate II

How to count distinct rows in DAX custom column?

Hellloooo

I have the following DAX formula that counts the number of rows based where the date ‘MMYYDD’ (in my calendar table) falls between the min and max dates (table1).

 

Count =

COUNTROWS (

    FILTER (

        ‘Table1',

        [MMYYDD] >= ' Table1' [MinDate]

            && [MMYYDD] < ' Table1'[MaxDate]

    )

)

Table1  
AccNumMinDateMaxDate
ACC5281   31/03/2021   31/03/2024   
ACC528131/03/202131/03/2024
ACC528131/03/202131/03/2024
ACC528131/03/202131/03/2024
ACC528131/03/202131/03/2024
ACC525517/01/202330/11/2023
ACC525517/01/202330/11/2023
ACC525517/01/202330/04/2023
ACC525517/01/202330/04/2023
ACC525417/01/202329/02/2024
ACC525417/01/202329/02/2024
ACC525417/01/202329/02/2024

 

Unfortunately, Table1 includes duplicate account numbers, and this inflates the figures considerably. Is it possible to amend the above formula so it only counts distinct rows from ‘Table1’ where my AccNum is distinct? I am unable to remove duplicates in PowerQuery as my min/max date calculations are created using DAX in ‘Table1’. This is my end output:-

 

Cal1 
MMYYDDCount
01/11/202181201
01/12/202180930
01/01/202280654
01/02/2022   80344   
01/03/202280166
01/04/202279635
01/05/202278999
01/06/202278366
01/07/202277729
01/08/202277210
01/09/202276604
01/10/202275846
01/11/202275394

 

Any help massively appreciated!

 

CF

1 ACCEPTED SOLUTION

VAR __tab = filter(SUMMARIZE('Table1',[column1],...), ...)

RETURN
countrows(__tab)

think that this virtual table is like a pivot so you get 1 line by accnum

View solution in original post

5 REPLIES 5
ClemFandango
Advocate II
Advocate II

Amazing stuff! Thanks again!!

you're welcome 🙂

in the first 25 days challenge of Curbal, there are quite some examples of such virtual tables... good source of learning...

ClemFandango
Advocate II
Advocate II

Many thanks marcl1, I really appreciate the response. Creating a VAR virtual table is a completley new concept to me. Do you have any examples of how I would do that? I am just checking that I am following you correctly, would the VAR virtual table condense Table1, providing just unique AccNum's?

VAR __tab = filter(SUMMARIZE('Table1',[column1],...), ...)

RETURN
countrows(__tab)

think that this virtual table is like a pivot so you get 1 line by accnum

marcl1
Helper II
Helper II

Hi,

you can create a VAR virtual table with the function summarize

then you make the countrows on this virtual table...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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