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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
PSB
Helper III
Helper III

Power Query, count number of occurrence in column

Power Query help

count number of repeating values in "Source-gNB" column and add "Count" column with the count.

 

S_NodeIdS_CellSource-gNBtravelDistancecount
LondonNewYorkMNJ06941A2_231-A_5201103.9612
     
     
     
     
     
     
1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@PSB OK, here's a Power Query solution as well. Add a custom column with this formula:

let
SourceGNB = [#"Source-gNB"],
Count = Table.RowCount(Table.SelectRows(#"Changed Type", each [#"Source-gNB"] = SourceGNB))
in
Count

Here is the full query from Advanced Editor:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("pZAxDoAgDEXvwoyE30KVkVWjFyCE+99CiYkaXCQOHX5++/rblNS6zVaCQySlVbwEDnVbhRhDLJ4sYA+HTZDaQSrrrwhx4xNBhrsRTYovCH4hZFgKSFyoiFroSMCj7xlHM+4w/dnevFCMZT7vzzs=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [S_NodeId = _t, S_Cell = _t, #"Source-gNB" = _t, travelDistance = _t, count = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"S_NodeId", type text}, {"S_Cell", type text}, {"Source-gNB", type text}, {"travelDistance", type number}, {"count", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let
SourceGNB = [#"Source-gNB"],
Count = Table.RowCount(Table.SelectRows(#"Changed Type", each [#"Source-gNB"] = SourceGNB))
in
Count)
in
    #"Added Custom"


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

2 REPLIES 2
Greg_Deckler
Super User
Super User

@PSB OK, here's a Power Query solution as well. Add a custom column with this formula:

let
SourceGNB = [#"Source-gNB"],
Count = Table.RowCount(Table.SelectRows(#"Changed Type", each [#"Source-gNB"] = SourceGNB))
in
Count

Here is the full query from Advanced Editor:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("pZAxDoAgDEXvwoyE30KVkVWjFyCE+99CiYkaXCQOHX5++/rblNS6zVaCQySlVbwEDnVbhRhDLJ4sYA+HTZDaQSrrrwhx4xNBhrsRTYovCH4hZFgKSFyoiFroSMCj7xlHM+4w/dnevFCMZT7vzzs=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [S_NodeId = _t, S_Cell = _t, #"Source-gNB" = _t, travelDistance = _t, count = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"S_NodeId", type text}, {"S_Cell", type text}, {"Source-gNB", type text}, {"travelDistance", type number}, {"count", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let
SourceGNB = [#"Source-gNB"],
Count = Table.RowCount(Table.SelectRows(#"Changed Type", each [#"Source-gNB"] = SourceGNB))
in
Count)
in
    #"Added Custom"


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

@PSB Well, of course the DAX for this is trivial but I suppose you want it in Power Query?

Count DAX = 
  VAR __SNodeId = [S_NodeId]
  VAR __SCell = [S_Cell]
  VAR __SourcegNB = [Source-gNB]
RETURN
  COUNTROWS(FILTER('Table',[S_NodeId] = __SNodeId && [S_Cell] = __SCell && [Source-gNB] = __SourcegNB ))


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
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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

Top Solution Authors
Top Kudoed Authors