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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register 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
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.