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
astokes
Regular Visitor

How to count occurrence of repeated text values in a column

Greetings,

 

I am new to Power BI and have encountered a snag that I would love help with troubleshooting.

 

I am working with a dataset from a user survey. Initially, I am concentrating on the Race and Region fields. I would like to display a "count" (not distinct) of how many times a standard text response occurs within a column by Region.

 

Here is what I would like the output to be:

RegionCount AsianCount BlackCount White
Midwest125
Northeast254
Pacific589
Southeast877
Southwest928
Total252433

 

Below is an example of the issue I am encountering: 

    
RegionCount AsianCount BlackCount White
Midwest111
Northeast222
Pacific555
Southeast888
Southwest999
Total252525

 

Please help and let me know if more information is needed?

 

Thank you.

 

A. Stokes

 

 

1 ACCEPTED SOLUTION

Hi @astokes,

 

If your table structure is similar to below, you can convert it to the same structure as I posted above by unpivoting [Column1] and [Column2] in Query Editor.

1.PNG

 

After unpivot

2.PNG

 

Alternatively, if you don't want to change original table structure, you can create a calculated table.

New table = UNION(SELECTCOLUMNS(Test1,"Region",Test1[Region],"Race",Test1[Column1]), SELECTCOLUMNS(Test1,"Region",Test1[Region],"Race",Test1[Column2]))

 

For more advice, please provide more detailed sample data in your data source.

 

Regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-yulgu-msft
Employee
Employee

Hi @astokes,

 

Suppose your source table is like:

1.PNG

 

To display data in a matrix visual, please see below screenshot.

2.PNG

 

To show data in a clustered column chart visual, please see:

3.PNG

 

If you need to show count results in a table visual, you need to create measures like below:

Count Asian =
CALCULATE (
    COUNTROWS ( 'Region and race' ),
    FILTER ( 'Region and race', 'Region and race'[Race] = "Asian" )
)

Count Black =
CALCULATE (
    COUNTROWS ( 'Region and race' ),
    FILTER ( 'Region and race', 'Region and race'[Race] = "Black" )
)

Count White =
CALCULATE (
    COUNTROWS ( 'Region and race' ),
    FILTER ( 'Region and race', 'Region and race'[Race] = "White" )
)

4.PNG

 

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-yulgu-msft,

 

Thank you for the tips.

 

Unfortunately, my data source looks like this:

RegionAsianBlack/African American
Northeast  
NortheastAsianBlack/African American
Northeast  
NortheastAsianBlack/African American
NortheastAsianBlack/African American
NortheastAsianBlack/African American
NortheastAsianBlack/African American
NortheastAsianBlack/African American
Northeast  
Northeast  
Northeast  
Northeast  
NortheastAsianBlack/African American
NortheastAsianBlack/African American
NortheastAsianBlack/African American
Northeast  
Northeast  
NortheastAsianBlack/African American
NortheastAsianBlack/African American
NortheastAsianBlack/African American

 

I have this data source format for several survey response types (i.e., gender, ethnicity, etc.). Somehow, the counts in table visuals calculated properly for some values from some data sources, but not all of them. I'll create new measures instead as suggested and see if that resolves my issue. 

 

Thanks again. 

Hi @astokes,

 

If your table structure is similar to below, you can convert it to the same structure as I posted above by unpivoting [Column1] and [Column2] in Query Editor.

1.PNG

 

After unpivot

2.PNG

 

Alternatively, if you don't want to change original table structure, you can create a calculated table.

New table = UNION(SELECTCOLUMNS(Test1,"Region",Test1[Region],"Race",Test1[Column1]), SELECTCOLUMNS(Test1,"Region",Test1[Region],"Race",Test1[Column2]))

 

For more advice, please provide more detailed sample data in your data source.

 

Regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Duly noted to add more detail in the future. This did the trick. Thank you for helping me prevent pulling the rest of my hair out.

 

Have a great weekend!

 

Akissi

Anonymous
Not applicable

Is this a Table visualization or a Matrix?

 

If you use a Matrix with "Region" in the Rows section and "Race" in the Columns section, then your Count measure in the Values, it should work out.

Thank you. I will try that solution. Also, to answer your question - this will be both a table and chart visualization.

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.