Forum Discussion
PBIDEV_10
4 years agoHelper II
Denormalized table for project data
Hello Gurus I have an excel file as an input with project data. The data shows how many departments have worked on the project. The raw data looks like this: Project name Project description ...
- 4 years ago
Ahh, i see.
I uploaded a .pbix here.
https://drive.google.com/drive/folders/1AjePk7NUXAloXHr42BEa2lDOr5dQr2Wg
NickolajJessen
4 years agoSolution Sage
Paste this into advanced query editor. See if it gives you a clue.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZY8xT8QwDIX/itUJJMTRrp16hYGBBbGdbnBTq41InCp2KvHvcSMdILG9OO/587tcmhFlBXQuFVbPS/PQjCluyJ4EdEUFzAScFNIU/EIzaIKZgt8pAzIXDLe0wN1wU4PTe4hFFCYCnAIdsYWYMir9y+lKUSjshpxQjJHYBH+CZmRBpz6xPNppz373Yg94/bAlM8x+8Yqhh5+PN2RcKBJrNTgLlqDI7uuPqe5eUxErDFvJbjVq9U/HjESs4k4hbceiyq0ccNYoRWsulHfvSHp4J5u/iB69fuE9DOcRzsaxdHtq21P31LVVd4fsmuv1Gw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Project name" = _t, #"Project description" = _t, Division = _t, Department = _t, #"Start date" = _t, #"End date" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Project name", type text}, {"Project description", type text}, {"Division", type text}, {"Department", type text}, {"Start date", type date}, {"End date", type date}}),
#"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Start date", "End date"}),
#"Split Column by Delimiter1" = Table.SplitColumn(#"Removed Columns", "Department", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"Department.1", "Department.2", "Department.3"}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Split Column by Delimiter1", "Division", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"Division.1", "Division.2", "Division.3"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Division.1", type text}, {"Division.2", type text}, {"Division.3", type text}}),
All = Table.UnpivotOtherColumns(#"Changed Type1", {"Project name", "Project description"}, "Attribute", "Value"),
Divisions = Table.SelectRows(All, each ([Attribute] = "Division.1" or [Attribute] = "Division.2" or [Attribute] = "Division.3")),
#"Added Index" = Table.AddIndexColumn(Divisions, "Index", 0, 1, Int64.Type),
Divisions2 = Table.RemoveColumns(#"Added Index",{"Attribute"}),
Custom1 = All,
Departments = Table.SelectRows(Custom1, each ([Attribute] = "Department.1" or [Attribute] = "Department.2" or [Attribute] = "Department.3")),
#"Added Index1" = Table.AddIndexColumn(Departments, "Index", 0, 1, Int64.Type),
Departments2 = Table.RemoveColumns(#"Added Index1",{"Attribute"}),
#"Merged Queries" = Table.NestedJoin(Departments2, {"Project description", "Project name", "Index"}, Divisions2, {"Project description", "Project name", "Index"}, "Removed Columns1", JoinKind.LeftOuter),
#"Expanded Removed Columns1" = Table.ExpandTableColumn(#"Merged Queries", "Removed Columns1", {"Value"}, {"Value.1"}),
#"Reordered Columns" = Table.ReorderColumns(#"Expanded Removed Columns1",{"Project name", "Project description", "Value", "Value.1", "Index"}),
#"Removed Columns1" = Table.RemoveColumns(#"Reordered Columns",{"Index"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns1",{{"Value.1", "Divisions"}, {"Value", "Departments"}})
in
#"Renamed Columns"PBIDEV_10
4 years agoHelper II
Thank you for your reply. This works to split the division and department.
But I have a question. How can I assure that we choose the correct division for the department. how can I use the division and department tables vi have already? Because I dont know if the raw data comes in the sequence that department1 has division1 and so on.
regards
PP