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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

COUNTROWS of DISTINCT strings/values across multiple columns

I have a table with 3 columns like this:

 

Table1

lotwijnants_3-1687937544508.png

 

 

In PowerBI I would like to count the frequency of each unique value/string and get it in a seperate table like this:

 

Table2

lotwijnants_4-1687937595495.png

 

I'm finding all different ways of getting a list of the unique values like this:

 

 

 

Table2 = 
     DISTINCT(
          UNION(
              DISTINCT('Table1'[Column1]),
              DISTINCT('Table1'[Column2]),
              DISTINCT('Table1'[Column3])
          )
     )

 

 

 

 

Which now only gives me a list of distinct values/strings, but not with the count:

lotwijnants_5-1687937673779.png

 

 

And I don't know how to get the count column with it.

Could someone help me to get the counts with it as well?

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

Try

Combined table =
VAR Col1 =
    ADDCOLUMNS (
        DISTINCT ( 'Table'[Column1] ),
        "@count", CALCULATE ( COUNTROWS ( 'Table' ) )
    )
VAR Col2 =
    ADDCOLUMNS (
        DISTINCT ( 'Table'[Column2] ),
        "@count", CALCULATE ( COUNTROWS ( 'Table' ) )
    )
VAR Col3 =
    ADDCOLUMNS (
        DISTINCT ( 'Table'[Column3] ),
        "@count", CALCULATE ( COUNTROWS ( 'Table' ) )
    )
VAR Result =
    GROUPBY (
        UNION ( Col1, Col2, Col3 ),
        [Column1],
        "Total count", SUMX ( CURRENTGROUP (), [@count] )
    )
RETURN
    Result

View solution in original post

1 REPLY 1
johnt75
Super User
Super User

Try

Combined table =
VAR Col1 =
    ADDCOLUMNS (
        DISTINCT ( 'Table'[Column1] ),
        "@count", CALCULATE ( COUNTROWS ( 'Table' ) )
    )
VAR Col2 =
    ADDCOLUMNS (
        DISTINCT ( 'Table'[Column2] ),
        "@count", CALCULATE ( COUNTROWS ( 'Table' ) )
    )
VAR Col3 =
    ADDCOLUMNS (
        DISTINCT ( 'Table'[Column3] ),
        "@count", CALCULATE ( COUNTROWS ( 'Table' ) )
    )
VAR Result =
    GROUPBY (
        UNION ( Col1, Col2, Col3 ),
        [Column1],
        "Total count", SUMX ( CURRENTGROUP (), [@count] )
    )
RETURN
    Result

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.