Forum Discussion

Nipius's avatar
Nipius
Icon for Advocate I rankAdvocate I
7 years ago
Solved

Creating unique value if value already exists

Hi all!

 

I have a query including a column with duplicate values. For the purpose of my table, I'd like to add another column where I add another character (for example "A" or "1") to the duplicate of a value.

 

For example, in case of

58379

58379

58379

58379

93850

39412

39412

 

I'd like the first value to keep as is, but change the other duplicates and ignore the unique values. The above would then result in

58379

58379A

58379AA

58379AAA

93850

39412

39412A

 

Is there a way for me to accomplish this? Thanks in advance!

9 Replies

  • Nipius copy these steps into your table using query editor.

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMrUwNrdUitUhxLI0tjA1ALOMLU0MjZBZsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Id = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Id", Int64.Type}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"Id"}, {{"Count", each  Table.AddIndexColumn(_, "Rank", 0)}}),
        #"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"Rank"}, {"Rank"}),
        #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Count",{{"Rank", Int64.Type}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type1", "New Id", each Number.ToText([Id]) &
    (
    if [Rank] > 0 then "-" & Number.ToText([Rank]) else ""
    )),
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Id", "Rank"})
    in
        #"Removed Columns"
    • Nipius's avatar
      Nipius
      Icon for Advocate I rankAdvocate I

      Thanks parry2k !

       

      I've added this as a Custom Column, but there is not a reference to the particular column I want to get the values from. It now shows me the numbers I mentioned below, which was actually just an example. Am I missing something? :)

      • parry2k's avatar
        parry2k
        Icon for Super User rankSuper User

        Nipius if you share your full sample dataset it will help, I just gave you the solution based on what you posted originally.