let
Source = Table.FromRows (
Json.Document (
Binary.Decompress (
Binary.FromText (
"rZHPasMwDMZfReSsQ1boA6RZRks2NpqWHUIPonGCWSpn/rOtbz/bDbRkoacdDLIl6/vpU10nFfXCQLF9SzB5wMUyxTRNfbzhRhLCvvSnyhAyZ/zrTlMjuUNYC/o6Q/Hp5HASbH0qNkJ4kkx8FAivg0kOWCe5cmz1Gd5lI8D/l+wb+PplOpWqMn/JFRvX2ygyqs00X29j75UmDhVQ/AyCjZjMEMH3pY8muAgvxK6lo3X6RuAu72LKe3Hkyhsyu+vcK6U+oBRiCHyVau036Qg4M/fF5/sWI9xaM+UPyqM7Uf1RdtJSD3lPxmilTgY23GoKg8xs+T8Q/u4IIWA9i4760ZfDLw==",
BinaryEncoding.Base64
),
Compression.Deflate
)
),
let
_t = ( ( type nullable text ) meta [ Serialized.Text = true ] )
in
type table [
#"Cost Item" = _t,
Value = _t,
Location = _t,
Business = _t,
Department = _t
]
),
ChangedType = Table.TransformColumnTypes (
Source,
{
{ "Cost Item", type text },
{ "Value", Int64.Type },
{ "Location", type text },
{ "Business", type text },
{ "Department", type text }
}
),
Crossjoin = Table.AddColumn (
ChangedType,
"Test",
each
let
CurrentRow = _,
SplitDepartment = Text.Split ( CurrentRow[Department], ", " ),
SplitLocation = Text.Split ( CurrentRow[Location], ", " ),
SplitBusiness = Text.Split ( CurrentRow[Business], ", " ),
LocationListToTable = Table.RenameColumns (
Table.FromList ( SplitLocation ),
{ "Column1", "Location" }
),
AddBusiness = Table.AddColumn (
LocationListToTable,
"Business",
each SplitBusiness
),
AddDepartment = Table.AddColumn ( AddBusiness, "Department", each SplitDepartment ),
ExpandLocation = Table.ExpandListColumn ( AddDepartment, "Business" ),
ExpandBusiness = Table.ExpandListColumn ( ExpandLocation, "Department" ),
RowCount = Table.RowCount ( ExpandBusiness ),
AddAllocation = Table.AddColumn (
ExpandBusiness,
"Allocated Amount",
each CurrentRow[Value] / RowCount
)
in
AddAllocation
),
RemoveOtherCols = Table.SelectColumns ( Crossjoin, { "Cost Item", "Test" } ),
ExpandTest = Table.ExpandTableColumn (
RemoveOtherCols,
"Test",
{ "Location", "Department", "Business", "Allocated Amount" },
{ "Location", "Department", "Business", "Allocated Amount" }
),
ChangedType2 = Table.TransformColumnTypes (
ExpandTest,
{
{ "Cost Item", type text },
{ "Department", type text },
{ "Location", type text },
{ "Business", type text },
{ "Allocated Amount", type number }
}
)
in
ChangedType2