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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
joshua3m
Frequent Visitor

Count Table Distinct

Hello, 

I'm trying my journey with dax and i step into issue which i can't find a solution...  
I have table with CityLocation and Value and want count number of CityLocation where value is > 0.  

For below result it should be 2.  

 

I can get eaisly count of CityLocation where Value is >0 however how i can count unique City ? 

 

CityLocationValue
Torotno10
Toronto13
NewYork20
Toronto3-1
Denver10
Denver21
1 ACCEPTED SOLUTION

@joshua3m 
I can assume from your code that Value is a measure. In this case please try

COUNT =
COUNTROWS (
    DISTINCT (
        SELECTCOLUMNS (
            FILTER ( VALUES ( 'Table'[CITYLOCATION] ), [VALUE] > 0 ),
            "City", LEFT ( 'Table'[CITYLOCATION], LEN ( 'Table'[CITYLOCATION] ) - 1 )
        )
    )
)

 

 

View solution in original post

3 REPLIES 3
tamerj1
Super User
Super User

Hi @joshua3m 
Please try

Count =
CALCULATE ( DISTINCTCOUNT ( 'Table'[CityLocation] ), 'Table'[Value] > 0 )

Hi Tamerj , 

Would this not calculate distinct only for CityLocation where i want actually look into City and not City Location combine ?   

I was trying to do as below: 

 

 

COUNT: 
COUNTROWS( 
 FILTER(
   ADDCOLUMNS( 
          VALUES(LEFT([CITYLOCATION],LEN[CITYLOCATION]-1), 
             "STOCK" , ([VALUE]) 
              ), 
             [STOCK] >0
        )
)

 

 


@tamerj1 wrote:

Hi @joshua3m 
Please try

 

Count =
CALCULATE ( DISTINCTCOUNT ( 'Table'[CityLocation] ), 'Table'[Value] > 0 )

 


 

@joshua3m 
I can assume from your code that Value is a measure. In this case please try

COUNT =
COUNTROWS (
    DISTINCT (
        SELECTCOLUMNS (
            FILTER ( VALUES ( 'Table'[CITYLOCATION] ), [VALUE] > 0 ),
            "City", LEFT ( 'Table'[CITYLOCATION], LEN ( 'Table'[CITYLOCATION] ) - 1 )
        )
    )
)

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors