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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
dbaber
Regular Visitor

Calculate sequential count of unique id in new field

Hello,

 

I am trying to sequentially number each time a repeaded ID is listed in a column. The table I am working with does not have a Key Field. To create a key field I would like to take the repeated ID in Column A and the the sequential number in Column B so I can create a concatentated unique field.

 

ID# of times the value occursConcatentated Key Field
1000110001
1000210002
1000310003
2000120001
3000130001
3000230002
3000330003
4000140001
4000240002
4000340003
5000150001

 

I've tried using Count, Distinctcount and Countrow functions, but I'm missing something.  

 

Thanks!

@dbaber

1 ACCEPTED SOLUTION
Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

Hi @dbaber - I have put together are example of how Power Query Table.Group function can be used to add index column based on the ID column.  To help you understand further please video this video on advanced Table.Group features: Advanced Group By Tricks in Power Query - YouTube

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFCK1cHGMIIxjDEYJrgZpmBGLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t]),
    #"Add Normal Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
    #"Group Row With ID Index" = Table.Group(#"Add Normal Index", {"ID"}, {{"ID Index", each Table.AddIndexColumn( _ , "ID Index", 1 , 1 ), type table [ID=nullable text, Index=Int64.Type, ID Index=Int64.Type]}}),
    #"ID Index" = Table.Combine( #"Group Row With ID Index"[ID Index] ),
    #"Add Final Index" = Table.AddColumn(#"ID Index", "Final ID Index", each Number.From([ID]) + [ID Index], Int64.Type)
in
    #"Add Final Index"

 

View solution in original post

1 REPLY 1
Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

Hi @dbaber - I have put together are example of how Power Query Table.Group function can be used to add index column based on the ID column.  To help you understand further please video this video on advanced Table.Group features: Advanced Group By Tricks in Power Query - YouTube

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFCK1cHGMIIxjDEYJrgZpmBGLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t]),
    #"Add Normal Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
    #"Group Row With ID Index" = Table.Group(#"Add Normal Index", {"ID"}, {{"ID Index", each Table.AddIndexColumn( _ , "ID Index", 1 , 1 ), type table [ID=nullable text, Index=Int64.Type, ID Index=Int64.Type]}}),
    #"ID Index" = Table.Combine( #"Group Row With ID Index"[ID Index] ),
    #"Add Final Index" = Table.AddColumn(#"ID Index", "Final ID Index", each Number.From([ID]) + [ID Index], Int64.Type)
in
    #"Add Final Index"

 

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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