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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Converting python code to PowerBI

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:

yuvan29_0-1715911292739.png

When I apply the python code to it, it results in this dataframe:

yuvan29_1-1715911352578.png

 

I would be grateful for any ideas, thank you

1 ACCEPTED SOLUTION
VahidDM
Super User
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!! 

LinkedIn | Twitter | Blog | YouTube 

View solution in original post

3 REPLIES 3
some_bih
Super User
Super User

Hi @Anonymous one options to get results like in jupyter cells view outuput for single column

Powerquery, Tab Transform and picture below

some_bih_0-1715926295515.png

 





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

Proud to be a Super User!






VahidDM
Super User
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!! 

LinkedIn | Twitter | Blog | YouTube 

Anonymous
Not applicable

Perfect this worked, thank you!

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors