Sure no worries.
I created a tRegion table
Based on the xlsx from my previous post, here’s the M code for that:
let
Source = Excel.Workbook(File.Contents(FileLocation), null, true),
tRegion_Table = Source{[Item="tRegion",Kind="Table"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(tRegion_Table,{{"Type", type text}, {"Region", type text}})
in
#"Changed Type"
.
and this is the result for the tData table
M code for that query:
let
Source = Excel.Workbook(File.Contents(FileLocation), null, true),
tData_Table = Source{[Item="tData",Kind="Table"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(tData_Table,{{"Date", type date}, {"Type", type text}, {"Number", Int64.Type}, {"Type2", type text}, {"Number ", Int64.Type}}),
#"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Changed Type", {{"Number", type text}}, "nl-NL"),{"Type", "Number"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Merged"),
#"Merged Columns1" = Table.CombineColumns(Table.TransformColumnTypes(#"Merged Columns", {{"Number ", type text}}, "nl-NL"),{"Type2", "Number "},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Merged.1"),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Merged Columns1", {"Date"}, "Attribute", "Value"),
#"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Attribute"}),
#"Split Column by Position" = Table.SplitColumn(#"Removed Columns", "Value", Splitter.SplitTextByPositions({0, 1}, false), {"Value.1", "Value.2"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Position",{{"Value.1", type text}, {"Value.2", Int64.Type}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type1", {"Value.1"}, tRegion, {"Type"}, "tRegion", JoinKind.LeftOuter),
#"Expanded tRegion" = Table.ExpandTableColumn(#"Merged Queries", "tRegion", {"Region"}, {"Region"}),
#"Renamed Columns" = Table.RenameColumns(#"Expanded tRegion",{{"Value.1", "Type"}, {"Value.2", "Number"}})
in
#"Renamed Columns"
.
Might I suggest creating a Parameter for the source location?
As you can see in all M codes ‘source’ lines above I use a Parameter to hold the file/source location.
I think it’s a best practice because when a location changes I only have to update this Parameter to restore all my queries.
I hope this is helpful.