I am working with an Excel file having import and export data between different countries for various shipping products, which looks pretty much like this:
The goal is to create a consolidated state pair that have a trade relation between them. So the final list for the above example should look something like this:
What would be the best way to go about this?
So assume your data is in a&b in the first screenshot, put this formula in column c =a1&b1
then hit enter, then drag the bottom right hand corner down so the formula works for all cells in that column. Then copy the column and paste it as values.
Then in column d, use the formula =countifs(c:c,c1) and drag it down in the same way. Now paste column d as values.
Finally, on the data tab, remove duplicates based on column c and then delete column c.
You can do this with Power Query, available in Windows Excel 2010+ and O365
M Code
let
Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Importing Country", type text}, {"Exporting Country", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Country", each List.Sort({[Importing Country],[Exporting Country]})),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Importing Country", "Exporting Country"}),
#"Extracted Values" = Table.TransformColumns(#"Removed Columns", {"Country", each Text.Combine(List.Transform(_, Text.From), ";"), type text}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values", "Country", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"Country.1", "Country.2"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Country.1", type text}, {"Country.2", type text}}),
#"Grouped Rows" = Table.Group(#"Changed Type1", {"Country.1", "Country.2"}, {{"Occurrences", each Table.RowCount(_), Int64.Type}})
in
#"Grouped Rows"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.