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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Toune84
Regular Visitor

Trouble counting occurence of same text value accross columns

Hello all,

 

I am new at PowerBi. I have issue counting occurences between distinct columns. I have several character displayed as shown here with their gender + the accessories they wear:

 

Woman3D GlassesLong HairSanta Claus Hat  
ManLong HairPolice CapBig BeardRoman Collar3D Glasses
Woman3D GlassesRoman Collar   

 

What I would like to get is a table counting how many time each accessorry has been used such as:

3D Glasses3
Big Beard1
Long Hair2
Police Cap1
Roman Collar2
Santa Claus Hat1

 

I have tried many things I found on the forum but I do not manage to make it work. 

Thanks for the help!

Toune84

1 ACCEPTED SOLUTION
Nathaniel_C
Community Champion
Community Champion

Hi @Toune84 ,
Try  this:

Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel

Here is your original table in Power Query.

Nathaniel_C_0-1653927998498.png

highlight gender and Unpivot other columns"

Nathaniel_C_1-1653928171124.png

Remove other columns

Nathaniel_C_2-1653928227805.png

Filter out the blanks

Nathaniel_C_3-1653928285734.png

Go to Transform tab, select groupby and you have your final table with names and counts

Nathaniel_C_4-1653928419784.png

Here is the code that you may post into advance editor in power query.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCs/PTcxT0lEydlFwz0ksLk4tBnJ88vPSFTwSM4uA7ODEvJJEBeecxNJioFAJUEQBjGN1opV8wVqRVQfk52Qmpyo4JxYAOU6Z6QpOqYlFKUB2EMgeBef8nJzEIlTrQAZhdQWaFpC1IBQbCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t, #"(blank).4" = _t, #"(blank).5" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}, {"(blank).3", type text}, {"(blank).4", type text}, {"(blank).5", type text}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"(blank)", "Gender"}, {"(blank).1", "C1"}, {"(blank).2", "C2"}, {"(blank).3", "C3"}, {"(blank).4", "C4"}, {"(blank).5", "C5"}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Renamed Columns", {"Gender"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Gender", "Attribute"}),
    #"Filtered Rows" = Table.SelectRows(#"Removed Columns", each ([Value] <> "" and [Value] <> " ")),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Value"}, {{"Count", each Table.RowCount(_), Int64.Type}})
in
    #"Grouped Rows"

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

5 REPLIES 5
Nathaniel_C
Community Champion
Community Champion

Hi @Toune84 ,
Try  this:

Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel

Here is your original table in Power Query.

Nathaniel_C_0-1653927998498.png

highlight gender and Unpivot other columns"

Nathaniel_C_1-1653928171124.png

Remove other columns

Nathaniel_C_2-1653928227805.png

Filter out the blanks

Nathaniel_C_3-1653928285734.png

Go to Transform tab, select groupby and you have your final table with names and counts

Nathaniel_C_4-1653928419784.png

Here is the code that you may post into advance editor in power query.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCs/PTcxT0lEydlFwz0ksLk4tBnJ88vPSFTwSM4uA7ODEvJJEBeecxNJioFAJUEQBjGN1opV8wVqRVQfk52Qmpyo4JxYAOU6Z6QpOqYlFKUB2EMgeBef8nJzEIlTrQAZhdQWaFpC1IBQbCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t, #"(blank).4" = _t, #"(blank).5" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}, {"(blank).3", type text}, {"(blank).4", type text}, {"(blank).5", type text}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"(blank)", "Gender"}, {"(blank).1", "C1"}, {"(blank).2", "C2"}, {"(blank).3", "C3"}, {"(blank).4", "C4"}, {"(blank).5", "C5"}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Renamed Columns", {"Gender"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Gender", "Attribute"}),
    #"Filtered Rows" = Table.SelectRows(#"Removed Columns", each ([Value] <> "" and [Value] <> " ")),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Value"}, {{"Count", each Table.RowCount(_), Int64.Type}})
in
    #"Grouped Rows"

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks a lot for the answer! It works perfectly 😉

Hi @Toune84 ,
You are very welcome!

Thank you,

Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




amitchandak
Super User
Super User

@Toune84 , Do your distinct list of names?

 

Then you can create a measure like

countrows(filter(Table, search(max(Keyword[KeyWord]) , Table[Column],,0) >0 ) )

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Thanks for the answer! Unfortunately, I still do not manage to make it work.
 
Yes I have a list of all my accessesories called "Attributes list" in the table called Attributes (see screenshot)
 
All the occurences I want to find are in the columns '0', '1', '2', '3', '4', '5', '6', '7'
 
Can you please help me write the formula with the right table names and column names?
 
Thanks a lot for the help
 
Toune84_0-1653928110308.png

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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