Forum Discussion

TBStacey's avatar
TBStacey
Helper I
2 years ago
Solved

Concatanate values in the same column when defined criteria match from value in another column

I'm using Power Query in Power BI.   Here is an example of the data I'm looking at. The data is currently grouped so the # of rows with each "Test Interpretation" is displayed in the end column as ...
  • lbendlin's avatar
    2 years ago
    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("pdDRaoMwFAbgVzm4mw6Eqk1ivWxnxxxUhHknMqQNNNQmoind4Dz86mpkOuhadnc05Mt//iyzkijGxWbDm0Yo+R4fD/hWHKqSQ/pZcRuSQgsuNagaEqVKvsWUNxoiqXld1Vyfj5W8/AsLzWEtBl/FBz5ArU4NnITegW5PxPCulduZtVg+oesRimtR7mEi5LZ9sfp+8bFPgXG4SpFNvdnUczzSTvQyzRznLqhzSO8Q44yY5fHMpIXcQwvapgQThPYA66YfAKHsxn3o1X0YJf92wtUz+uz+fslwLcP8qmUEXC02mPs35mDjeoOOeYle0Z8Hf+Zwe8A1Oaw8/wI=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
        #"Split Column by Delimiter" = Table.SplitColumn(Source, "Column1", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), {"Column1.1", "Column1.2", "Column1.3", "Column1.4", "Column1.5", "Column1.6", "Column1.7", "Column1.8"}),
        #"Promoted Headers" = Table.PromoteHeaders(#"Split Column by Delimiter", [PromoteAllScalars=true]),
        #"Removed Columns" = Table.RemoveColumns(#"Promoted Headers",{""}),
        #"Changed Type" = Table.TransformColumnTypes(#"Removed Columns",{{"PIN", type text}, {"Accession_Num", Int64.Type}, {"Sample Type, Patient or Pooled", type text}, {"Test Interpretation", type text}, {"Test Date Min", type date}, {"Test Date Max", type date}, {"# rows with test interpretation", type text}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"PIN", "Accession_Num"}, {{"Sample Type, Patient or Pooled", each Text.Combine([#"Sample Type, Patient or Pooled"],"; "),type nullable text},{"Test Interpretation", each Text.Combine([Test Interpretation],"; "),type nullable text},{"Test Date Min", each List.Min([Test Date Min]), type nullable date}, {"Test Date Max", each List.Max([Test Date Max]), type nullable date}, {"# rows with test interpretation", each Text.Combine([#"# rows with test interpretation"],"; "), type nullable text}})
    in
        #"Grouped Rows"

    How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.