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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

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
tamerj1
Community Champion
Community Champion

@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
Community Champion
Community Champion

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 )

 


 

tamerj1
Community Champion
Community Champion

@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
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.