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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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"

@ 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!:
The Definitive Guide to Power Query (M)

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"

@ 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!:
The Definitive Guide to Power Query (M)

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 ))

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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