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
JMM414141
Frequent Visitor

Count True/False values in multiple columns

I have a table with about 50 columns with rows that either have True or False in them. Is it possible to count the number of times either true or false appears in each column without going through each column one by one?

4 REPLIES 4
camargos88
Community Champion
Community Champion

Hi @JMM414141 ,

 

Can you show some example ?



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

Proud to be a Super User!



ABC
TrueFalseTrue
FalseFalseTrue

 

 ABC
True102
False12

0

 

 

So I have something like the first table and im trying to get something like the 2nd table where it shows the number of true/false that exist in each column.

Hi @JMM414141 ,

 

This is a Power Query solution, create a blank query and past this m code:

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCikqTVXSUXJLzCkG0WBurE40XABVIhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [A = _t, B = _t, C = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"A", type logical}, {"B", type logical}, {"C", type logical}}),
Table = Table.Combine({ Table.AddColumn(#"Changed Type", "Type", each "True"), Table.AddColumn(#"Changed Type", "Type", each "False") }),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Table, {"Type"}, "Attribute", "Value"),
#"Added Custom" = Table.AddColumn(#"Unpivoted Other Columns", "Custom", each if Logical.FromText([Type]) = [Value] then 1 else 0),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Value"}),
#"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Attribute]), "Attribute", "Custom", List.Sum),
#"Changed Type1" = Table.TransformColumnTypes(#"Pivoted Column",{{"Type", type logical}, {"A", Int64.Type}, {"B", Int64.Type}, {"C", Int64.Type}})
in
#"Changed Type1"

 

Capture.PNG



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

Proud to be a Super User!



AntrikshSharma
Community Champion
Community Champion

Why not unpivot the data?

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.

Top Solution Authors