Forum Discussion

Kudol's avatar
Kudol
Regular Visitor
9 years ago
Solved

How to create new column based on duplicate values

Hello, i need help with creating new column. It is hard to explain so here is example:   Table 1. GUID; Email; 1111; [email protected]; 1111; [email protected] 1112; [email protected] 1113; 13@g...
  • ImkeF's avatar
    9 years ago

    This is a pivot-operation that you perform in the query-editor:

     

    let
        Source = Source,
        #"Grouped Rows" = Table.Group(Source, {"GUID"}, {{"Partition", each _, type table}}),
        #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Partition], "Index", 1,1)),
        #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
        #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"GUID", "Email", "Index"}, {"GUID", "Email", "Index"}),
        #"Added Custom1" = Table.AddColumn(#"Expanded Custom", "Custom", each "Email "),
        #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Added Custom1", {{"Index", type text}}, "de-DE"),{"Custom", "Index"},Combiner.CombineTextByDelimiter(":", QuoteStyle.None),"Merged"),
        #"Pivoted Column" = Table.Pivot(#"Merged Columns", List.Distinct(#"Merged Columns"[Merged]), "Merged", "Email")
    in
        #"Pivoted Column"

    Please let me know if you need help implementing this.

  • v-qiuyu-msft's avatar
    v-qiuyu-msft
    9 years ago

    Hi Kudol,

     

    In your  scneaior, I would suggest you place those email values within each GUID group in one column, you can refer to below sample:

     

    Rank = RANKX(FILTER(ALL(Table1),'Table1'[GUID]=EARLIER(Table1[GUID])),'Table1'[Email],,ASC)

     

    Rnk = IF('Table1'[Rank]<>1,'Table1'[Rank]-1)

     

    ParEmail = CALCULATE(FIRSTNONBLANK('Table1'[Email],1),FILTER(ALLEXCEPT(Table1,'Table1'[GUID]),'Table1'[Rank]=EARLIER(Table1[Rnk])))

     

    Emails = CALCULATE(PATH(Table1[Email],Table1[ParEmail]),CALCULATETABLE(FILTER('Table1',Table1[Rank]=MAX('Table1'[Rank])),ALLEXCEPT(Table1,'Table1'[GUID])))

     

     

    Best Regards,
    Qiuyun Yu