Function ConcatIf(Src As Range, ChkRng As Range, myVal As Variant, Optional Sep As String) As String
Dim c As Range
Dim retVal As String
Dim i As Integer
retVal = ""
i = 1
For Each c In ChkRng
If c = myVal Then
retVal = retVal + Src(i) + Sep
End If
i = i + 1
Next
ConcatIf = Left(retVal, Len(retVal) - Len(Sep))
End Function
let
Source = Excel.Workbook(File.Contents("C:\Users\nebusud\Downloads\Concat.xlsx"), null, true),
Table1_Table = Source{[Item="Table1",Kind="Table"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(Table1_Table,{{"Store ID", Int64.Type}, {"Equipment", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.From([Store ID])&"-" &[Equipment]),
#"Pivoted Column" = Table.Pivot(#"Added Custom", List.Distinct(#"Added Custom"[Equipment]), "Equipment", "Custom"),
#"Added Custom1" = Table.AddColumn(#"Pivoted Column", "Equipment", each Text.Trim(Text.AfterDelimiter([Cash Register],"-")&"&"&Text.AfterDelimiter([CCTV],"-"),"&")),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Cash Register", "CCTV"})
in
#"Removed Columns"
Hi:
This is easy to do with a power query, find the attached. The result is in green table.
ThanksCode:let Source = Excel.Workbook(File.Contents("C:\Users\nebusud\Downloads\Concat.xlsx"), null, true), Table1_Table = Source{[Item="Table1",Kind="Table"]}[Data], #"Changed Type" = Table.TransformColumnTypes(Table1_Table,{{"Store ID", Int64.Type}, {"Equipment", type text}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.From([Store ID])&"-" &[Equipment]), #"Pivoted Column" = Table.Pivot(#"Added Custom", List.Distinct(#"Added Custom"[Equipment]), "Equipment", "Custom"), #"Added Custom1" = Table.AddColumn(#"Pivoted Column", "Equipment", each Text.Trim(Text.AfterDelimiter([Cash Register],"-")&"&"&Text.AfterDelimiter([CCTV],"-"),"&")), #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Cash Register", "CCTV"}) in #"Removed Columns"
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.From([Store ID])&"-" &[Equipment]),
#"Pivoted Column" = Table.Pivot(#"Added Custom", List.Distinct(#"Added Custom"[Equipment]), "Equipment", "Custom"),
#"Added Custom1" = Table.AddColumn(#"Pivoted Column", "Equipment", each Text.Trim(Text.AfterDelimiter([Cash Register],"-")&"&"&Text.AfterDelimiter([CCTV],"-"),"&")),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Cash Register", "CCTV"})
in
#"Removed Columns"
Hi:
No, the M code I have given is from the start, if you already have codes that connect to source you do not need the lines to connect the source again. Open the excel file I have uploaded and go through the logic I have applied. You may have to look at the following lines, the logic are in these 4 lines.
Code:#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.From([Store ID])&"-" &[Equipment]), #"Pivoted Column" = Table.Pivot(#"Added Custom", List.Distinct(#"Added Custom"[Equipment]), "Equipment", "Custom"), #"Added Custom1" = Table.AddColumn(#"Pivoted Column", "Equipment", each Text.Trim(Text.AfterDelimiter([Cash Register],"-")&"&"&Text.AfterDelimiter([CCTV],"-"),"&")), #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Cash Register", "CCTV"}) in #"Removed Columns"
Thanks
let
Source = Excel.Workbook(File.Contents("C:\Users\nebusud\Downloads\Concat (3).xlsx"), null, true),
Table1_Table = Source{[Item="Table1",Kind="Table"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(Table1_Table,{{"Store ID", Int64.Type}, {"Equipment", type text}}),
#"Unique ID" = Table.AddColumn(#"Changed Type", "Custom", each Text.From([Store ID])&"-" &[Equipment]),
#"Pivoted Column" = Table.Pivot(#"Unique ID", List.Distinct(#"Unique ID"[Equipment]), "Equipment", "Custom"),
#"Merged Columns" = Table.CombineColumns(#"Pivoted Column",{"Cash Register", "CCTV", "Table"},Combiner.CombineTextByDelimiter("&", QuoteStyle.None),"Merged"),
#"Equipment" = Table.AddColumn(#"Merged Columns", "Equipment", each Text.Trim(Text.Remove([Merged],{"0".."9","-"}),"&")),
#"Removed Columns" = Table.RemoveColumns(Equipment,{"Merged"})
in
#"Removed Columns"