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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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!:
Mastering Power BI 2nd Edition

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!:
Mastering Power BI 2nd Edition

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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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