Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
I have a table in PowerBI which I want to transform using PowerQuery. I am trying to do the PowerQuery equivalent of applying the python function value_counts() to every column in the dataframe. However, I cannot find a way to do it.
df.apply(pd.Series.value_counts)
As an example, I have this dataframe:
When I apply the python code to it, it results in this dataframe:
I would be grateful for any ideas, thank you
Solved! Go to Solution.
Hi @Anonymous
You can use this code in Power Query, just update the Source:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKkvMKU2NN1TSgbKM4CwTOMsUiRWrg08PdnOw6UGwjLGy8NtjjNWV+O3BZiPQbbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Day 1" = _t, #"Day 2" = _t, #"Day 3" = _t, #"Day 4" = _t, #"Day 5" = _t]),
UnpivotedColumns = Table.UnpivotOtherColumns(Source, {}, "Attribute", "Value"),
GroupedRows = Table.Group(UnpivotedColumns, {"Attribute", "Value"}, {{"Count", each Table.RowCount(_), type number}}),
#"Pivoted Column" = Table.Pivot(GroupedRows, List.Distinct(GroupedRows[Attribute]), "Attribute", "Count", List.Sum)
in
#"Pivoted Column"
The sample file is attached.
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Hi @Anonymous one options to get results like in jupyter cells view outuput for single column
Powerquery, Tab Transform and picture below
Proud to be a Super User!
Hi @Anonymous
You can use this code in Power Query, just update the Source:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKkvMKU2NN1TSgbKM4CwTOMsUiRWrg08PdnOw6UGwjLGy8NtjjNWV+O3BZiPQbbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Day 1" = _t, #"Day 2" = _t, #"Day 3" = _t, #"Day 4" = _t, #"Day 5" = _t]),
UnpivotedColumns = Table.UnpivotOtherColumns(Source, {}, "Attribute", "Value"),
GroupedRows = Table.Group(UnpivotedColumns, {"Attribute", "Value"}, {{"Count", each Table.RowCount(_), type number}}),
#"Pivoted Column" = Table.Pivot(GroupedRows, List.Distinct(GroupedRows[Attribute]), "Attribute", "Count", List.Sum)
in
#"Pivoted Column"
The sample file is attached.
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Perfect this worked, thank you!
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 55 | |
| 34 | |
| 31 | |
| 19 | |
| 17 |
| User | Count |
|---|---|
| 74 | |
| 71 | |
| 38 | |
| 35 | |
| 25 |