cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Heidi Helper I
Helper I

Counting occurences in Power Query

Hi all, 

 

I found my self in need of counting occurences of values in Power Query. I want to higlight that this needs to be done in Power Query, not as a DAX - formula (that I can do).

 

Here's an example:

NamesCalculated values
Anne4
James2
Anne 4
Anne4
James2
Frank1
Anne4

 

So each row should have the value of the total appearances of the value in one column. I imagine this is possible, and perhaps this an absolute novice question. But I just can't figure it out, so here I am. 

1 ACCEPTED SOLUTION

Accepted Solutions
Super User III
Super User III

Re: Counting occurences in Power Query

Hi @Heidi ,

 

Do a Group By Name and select count Rows. Then just merge make the merge with the step before making the group by.

 

Check the code with the steps for a simple model. 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcszLS1WK1YlW8krMTS0Gs+BCWOTcihLzspEkYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Names = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Names"}, {{"Count", each Table.RowCount(_), type number}}),
    #"Merged Queries" = Table.NestedJoin(Source, {"Names"}, #"Grouped Rows", {"Names"}, "Count_Rows", JoinKind.LeftOuter),
    #"Expanded Count_Rows" = Table.ExpandTableColumn(#"Merged Queries", "Count_Rows", {"Count"}, {"Count"})
in
    #"Expanded Count_Rows"

Regards

Miguel Félix


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

Proud to be a Datanaut!

Check out my blog: Power BI em Português


View solution in original post

3 REPLIES 3
Super User IV
Super User IV

Re: Counting occurences in Power Query

I think you are looking for sub total

https://powerbloggerbi.com/2016/06/29/power-query-total-and-subtotal/





Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
In case it does not help, please provide additional information and mark me with @
My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP,
HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Proud to be a Super User! Linkedin


Super User III
Super User III

Re: Counting occurences in Power Query

Hi @Heidi ,

 

Do a Group By Name and select count Rows. Then just merge make the merge with the step before making the group by.

 

Check the code with the steps for a simple model. 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcszLS1WK1YlW8krMTS0Gs+BCWOTcihLzspEkYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Names = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Names"}, {{"Count", each Table.RowCount(_), type number}}),
    #"Merged Queries" = Table.NestedJoin(Source, {"Names"}, #"Grouped Rows", {"Names"}, "Count_Rows", JoinKind.LeftOuter),
    #"Expanded Count_Rows" = Table.ExpandTableColumn(#"Merged Queries", "Count_Rows", {"Count"}, {"Count"})
in
    #"Expanded Count_Rows"

Regards

Miguel Félix


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

Proud to be a Datanaut!

Check out my blog: Power BI em Português


View solution in original post

Heidi Helper I
Helper I

Re: Counting occurences in Power Query

Awesome, works like a charm! Thanks @MFelix , you totally saved my day! 

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Join THE global Microsoft Power Platform event series.

Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors