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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

How to create a custom column that counts repeat objects in two columns.

Hi, I have data such that many values can appear mapped to one another multiple times. In the below example, cho@gmail.com  is mapped to click twice.

 

cho@gmail.comclick
hint@yahoo.comclick
hint@yahoo.comview
cho@gmail.comclick

 

I would like to add a column to the dataset using powerquery that displays the number of click actions taken by a user. It would look something like this...

 

cho@gmail.com 

click

2
hint@yahoo.comclick1
hint@yahoo.comview1
cho@gmail.comclick2

 

Is there any way to do this?

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@Anonymous Try this:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSs7Id0jPTczM0UvOz1XSUUrOyUzOVorViVbKyMwrcahMzMjPJyxVlplaDpbBYVwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [email = _t, #"type" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"email", type text}, {"type", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"email", "type"}, {{"Count", each Table.RowCount(_), Int64.Type}, {"Table", each _, type table [email=nullable text, type=nullable text]}}),
    #"Removed Columns" = Table.RemoveColumns(#"Grouped Rows",{"email", "type"}),
    #"Expanded Table" = Table.ExpandTableColumn(#"Removed Columns", "Table", {"email", "type"}, {"Table.email", "Table.type"})
in
    #"Expanded Table"


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

@Greg_Deckler is there a way to generalize the format to be applied to any table?

@Anonymous It's applicable to any table. You add an aggregation (Group By) step that groups by the columns you need it to group by. You have 2 aggregations. One is a Count of rows and one is "all rows". You end up with a table of your grouping columns along with the 2 aggregations. You then remove any columns other than the aggregation columns. Then you expand the aggregation column containing the Table.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Super User
Super User

@Anonymous Try this:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSs7Id0jPTczM0UvOz1XSUUrOyUzOVorViVbKyMwrcahMzMjPJyxVlplaDpbBYVwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [email = _t, #"type" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"email", type text}, {"type", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"email", "type"}, {{"Count", each Table.RowCount(_), Int64.Type}, {"Table", each _, type table [email=nullable text, type=nullable text]}}),
    #"Removed Columns" = Table.RemoveColumns(#"Grouped Rows",{"email", "type"}),
    #"Expanded Table" = Table.ExpandTableColumn(#"Removed Columns", "Table", {"email", "type"}, {"Table.email", "Table.type"})
in
    #"Expanded Table"


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.