Power Query - Duplication - groupedrows

Dancarro

Board Regular
Joined
Feb 23, 2013
Messages
72
Hi
I have something similar to the below

Columns2Columns3Columns4Columns5Columns6Columns
Transactionnullnull1nullnull
Bank refnullnull1anullnull
Transactionnullnull1nullnull
Currencynullnulleurnullnull
Bank Refnullnull2nullnull
Transactionnullnull2anullnull
Currencynullnulleurnullnull

Outcome

TransactionBank refCurrency
11aeur
1
2a2eur

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type any}, {"Column2", type any}, {"Column3", type any}, {"Column4", type any}, {"Column5", type any}, {"Column6", type any}, {"Column7", type any}, {"Column8", type any}, {"Column9", type any}, {"Column10", type any}, {"Column11", type any}, {"Column12", type any}, {"Column13", type any}, {"Column14", type any}, {"Column15", type any}, {"Column16", type any}, {"Column17", type text}, {"Column18", type any}, {"Column19", type any}, {"Column20", type any}, {"Column21", type any}, {"Column22", type any}, {"Column23", type any}, {"Column24", type any}, {"Column25", type any}, {"Column26", type any}, {"Column27", type any}, {"Column28", type any}, {"Column29", type any}, {"Column30", type any}, {"Column31", type any}, {"Column32", type any}}),
#"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Column1"}),
#"Removed Blank Rows" = Table.SelectRows(#"Removed Columns", each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null})))
in
#"Removed Blank Rows"

I tried using the following by using Grouped Rows but it doesn't work

'GroupedRows = Table.Group(ChangedType, {"Type"}, {{"DistinctValues", each _[Value]}}),
Output = Table.FromColumns(GroupedRows[DistinctValues], GroupedRows[Type])
in
Output'

Any suggestions on how to place the value of Col2 across and the values of col5 under

Kind Regards,
Dan
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
I got part way with this code. But I think there might be an inconsistency in your source data as there is no obvious way of knowing which entries are grouped together. I think you started on the right track using Group, but perhaps the code below will help: I chose 'all rows' as the aggregation when grouping the rows.

Rich (BB code):
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Columns2", type text}, {"Columns3", type any}, {"Columns4", type any}, {"Columns5", type any}, {"Columns6", type any}, {"Columns", type any}}),
    #"Capitalized Each Word" = Table.TransformColumns(#"Changed Type",{{"Columns2", Text.Proper, type text}}),
    #"Removed Other Columns" = Table.SelectColumns(#"Capitalized Each Word",{"Columns2", "Columns5"}),
    #"Grouped Rows" = Table.Group(#"Removed Other Columns", {"Columns2"}, {{"Count", each _, type table [Columns2=text, Columns5=anynonnull]}}),
    #"Transposed Table" = Table.Transpose(#"Grouped Rows"),
    #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Transaction", type any}, {"Bank Ref", type any}, {"Currency", type any}}),
    #"Expanded Transaction" = Table.ExpandTableColumn(#"Changed Type1", "Transaction", {"Columns5"}, {"Transaction.Columns5"}),
    #"Expanded Bank Ref" = Table.ExpandTableColumn(#"Expanded Transaction", "Bank Ref", {"Columns5"}, {"Bank Ref.Columns5"}),
    #"Expanded Currency" = Table.ExpandTableColumn(#"Expanded Bank Ref", "Currency", {"Columns5"}, {"Currency.Columns5"}),
    #"Removed Duplicates" = Table.Distinct(#"Expanded Currency")
in
    #"Removed Duplicates"
 
Upvote 0
just for fun
try:
tir.png

Rich (BB code):
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    TSC = Table.SelectColumns(Source,{"Columns2", "Columns5"}),
    Proper = Table.TransformColumns(TSC,{{"Columns2", Text.Proper, type text}}),
    TIR = Table.InsertRows(Proper,1,{[Columns2 = "Bank Ref", Columns5 = 0],[Columns2 = "Currency", Columns5 = 0]}),
    Text = Table.TransformColumnTypes(TIR,{{"Columns5", type text}}),
    Group = Table.Group(Text, {"Columns2"}, {{"Count", each _, type table}}),
    List = Table.AddColumn(Group, "List", each [Count][Columns5]),
    Extract = Table.TransformColumns(List, {"List", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    Split = Table.SplitColumn(Extract, "List", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"List.1", "List.2", "List.3"}),
    RC = Table.RemoveColumns(Split,{"Count"}),
    Transpose = Table.Transpose(RC),
    Promote = Table.PromoteHeaders(Transpose, [PromoteAllScalars=true]),
    Replace = Table.ReplaceValue(Promote,"0",null,Replacer.ReplaceValue,{"Transaction", "Bank Ref", "Currency"})
in
    Replace
 
Upvote 0
I forgot about sort,
tir.png

so add last step:
Sort = Table.Sort(Replace,{{"Transaction", Order.Ascending}, {"Currency", Order.Descending}})
and you've exactly what you want
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,154
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top