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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
stribor45
Post Prodigy
Post Prodigy

Counting only unique rows

Can this code be improved to count unique rows based on column A in MY_DATA table?

 

DEFINE

VAR B = 

COUNTROWS (FILTER 
            (
               'MY_DATA',
               'MY_DATA'[start time] IN DATESBETWEEN(
                                       'My_DATA'[start time], 
                                        DATE(2024, 7, 1), DATE(2024, 7, 31)
                                      )
           )
)
     
EVALUATE

{{B}}
1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@stribor45 So like this?

DEFINE

VAR B = 

COUNTROWS( DISTINCT( SELECTCOLUMNS(FILTER 
            (
               'MY_DATA',
               'MY_DATA'[start time] IN DATESBETWEEN(
                                       'My_DATA'[start time], 
                                        DATE(2024, 7, 1), DATE(2024, 7, 31)
                                      )
           ), "__Column", [A] ) )
)
     
EVALUATE

{{B}}


Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Greg_Deckler
Community Champion
Community Champion

@stribor45 So like this?

DEFINE

VAR B = 

COUNTROWS( DISTINCT( SELECTCOLUMNS(FILTER 
            (
               'MY_DATA',
               'MY_DATA'[start time] IN DATESBETWEEN(
                                       'My_DATA'[start time], 
                                        DATE(2024, 7, 1), DATE(2024, 7, 31)
                                      )
           ), "__Column", [A] ) )
)
     
EVALUATE

{{B}}


Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

 I need to adjust the code but I am confused as a distinct function only takes one column table as an argument.  This is the code 

EVALUATE
SELECTCOLUMNS (
                    FILTER (
                        'MY_DATA',
                        'MY_DATA'[start time]
                            IN DATESBETWEEN (
                                'MY_DATA'[start time],
                                DATE ( 2024, 5, 1 ),
                                DATE ( 2024, 5, 31 )
                            )
                    ),
                    "__Columns", [call duration],
                    "__Column", [id] 
)

Code above produces this table as a result (see the image below). Is there a way to remove duplicates row based on the [id]? Resulting table in the image produces duplicates and I need to end up with only two rows. 

 

stribor45_0-1723257497739.png

 

@stribor45 DISTINCT has a table version as well: DISTINCT (table) function (DAX) - DAX | Microsoft Learn



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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