Forum Discussion
COUNT IF in Power Query
- 6 years ago
Hi NumerENAP
You could try below M code
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCixNLS7JzM8zVNJRikwthpN++UqxOghpI5CQviMuaWM03SAyNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}}), #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Column1"}, "Attribute", "Value"), #"Grouped Rows" = Table.Group(#"Unpivoted Columns", {"Column1", "Value"}, {{"Count", each Table.RowCount(_), type number}}), #"Pivoted Column" = Table.Pivot(#"Grouped Rows", List.Distinct(#"Grouped Rows"[Value]), "Value", "Count", List.Sum), #"Merged Queries" = Table.NestedJoin(#"Pivoted Column", {"Column1"},#"Changed Type" , {"Column1"}, "Pivoted Column", JoinKind.LeftOuter), #"Expanded Pivoted Column" = Table.ExpandTableColumn(#"Merged Queries", "Pivoted Column", {"Column2", "Column3", "Column4"}, {"Pivoted Column.Column2", "Pivoted Column.Column3", "Pivoted Column.Column4"}) in #"Expanded Pivoted Column"If you just want to bold result in your result, you could try below M code
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCixNLS7JzM8zVNJRikwthpN++UqxOghpI5CQviMuaWM03SAyNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}}), #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Column1"}, "Attribute", "Value"), #"Grouped Rows" = Table.Group(#"Unpivoted Columns", {"Column1", "Value"}, {{"Count", each Table.RowCount(_), type number}}), #"Pivoted Column" = Table.Pivot(#"Grouped Rows", List.Distinct(#"Grouped Rows"[Value]), "Value", "Count", List.Sum), #"Replaced Value" = Table.ReplaceValue(#"Pivoted Column",null,0,Replacer.ReplaceValue,{"Yes", "No", "N/A"}) in #"Replaced Value"Best Regards,
Zoe ZhiIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi NumeroENAP ,
You will need to give us more information.
Please read this post to get your question answered more quickly:
https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
Thank you,
Nathaniel
- NumeroENAP6 years agoHelper III
This is an exemple of what I want (I want what's in bold) :
Column1 Column2 Column3 Column4 Nbof_yes Nbof_no Nbof_NA Question1 Yes Yes No 2 1 0 Question2 N/A Yes No 1 1 1 Question3 Yes Yes Yes 3 0 0 - dax6 years agoCommunity Support
Hi NumerENAP
You could try below M code
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCixNLS7JzM8zVNJRikwthpN++UqxOghpI5CQviMuaWM03SAyNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}}), #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Column1"}, "Attribute", "Value"), #"Grouped Rows" = Table.Group(#"Unpivoted Columns", {"Column1", "Value"}, {{"Count", each Table.RowCount(_), type number}}), #"Pivoted Column" = Table.Pivot(#"Grouped Rows", List.Distinct(#"Grouped Rows"[Value]), "Value", "Count", List.Sum), #"Merged Queries" = Table.NestedJoin(#"Pivoted Column", {"Column1"},#"Changed Type" , {"Column1"}, "Pivoted Column", JoinKind.LeftOuter), #"Expanded Pivoted Column" = Table.ExpandTableColumn(#"Merged Queries", "Pivoted Column", {"Column2", "Column3", "Column4"}, {"Pivoted Column.Column2", "Pivoted Column.Column3", "Pivoted Column.Column4"}) in #"Expanded Pivoted Column"If you just want to bold result in your result, you could try below M code
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCixNLS7JzM8zVNJRikwthpN++UqxOghpI5CQviMuaWM03SAyNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}}), #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Column1"}, "Attribute", "Value"), #"Grouped Rows" = Table.Group(#"Unpivoted Columns", {"Column1", "Value"}, {{"Count", each Table.RowCount(_), type number}}), #"Pivoted Column" = Table.Pivot(#"Grouped Rows", List.Distinct(#"Grouped Rows"[Value]), "Value", "Count", List.Sum), #"Replaced Value" = Table.ReplaceValue(#"Pivoted Column",null,0,Replacer.ReplaceValue,{"Yes", "No", "N/A"}) in #"Replaced Value"Best Regards,
Zoe ZhiIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- NumeroENAP6 years agoHelper III
I grasped the concept. It pretty much did nearly all that I wanted. I'll work with that. Thanks!