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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
kabra_ashish
Helper III
Helper III

Count recurrence of values from a column in Power query

How can I get a count of every value in a column in Power Query? More like Countif in Excel. This is certainly doable using DAX but I am interested in doing this in Power Query.

 

I am looking for the below "Count" field as an output using the Fruit field. 

 

Fruit          Count

Apple            3

Orange         1

Banana         2 

Apple           3

Apple           3

Banana         2

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

One of ways to achieve this in Power Query Editor is to write M code something like below.

Please check the below and the attached pbix file.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WciwoyElVitWJVvIvSsxLhzCdEvOAEMxEyCNYMOlYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Fruit = _t]),
    #"Merged Queries" = Table.NestedJoin(Source, {"Fruit"}, Source, {"Fruit"}, "Source", JoinKind.LeftOuter),
    #"Added Custom" = Table.AddColumn(#"Merged Queries", "Rowcount", each Table.RowCount ( [Source] ), Int64.Type),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Fruit", "Rowcount"})
in
    #"Removed Other Columns"

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

One of ways to achieve this in Power Query Editor is to write M code something like below.

Please check the below and the attached pbix file.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WciwoyElVitWJVvIvSsxLhzCdEvOAEMxEyCNYMOlYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Fruit = _t]),
    #"Merged Queries" = Table.NestedJoin(Source, {"Fruit"}, Source, {"Fruit"}, "Source", JoinKind.LeftOuter),
    #"Added Custom" = Table.AddColumn(#"Merged Queries", "Rowcount", each Table.RowCount ( [Source] ), Int64.Type),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Fruit", "Rowcount"})
in
    #"Removed Other Columns"

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
amitchandak
Super User
Super User

@kabra_ashish , Duplicate this table or create a new table using the fruit column.

Then group by and get count.

Merge the second table with the first one

 

https://docs.microsoft.com/en-us/power-query/group-by
Append : https://radacad.com/append-vs-merge-in-power-bi-and-power-query

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.