Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Hey guys,
Not sure if this is possible but... I'm trying to cleanse data (See link below).
What I need is to condence the Customer Acc column down so there are no duplicates, however Stage 1, Stage 2, Stage 3 needs to be merdged in a hierarchy type of system. With completed taking priority, then terminated, then abandoned, then blank/null.
For example
Acc Stage 1 Stage 2 Stage 3
1 Completed Abandoned terminated
1 Completed Completed Terminated
1 Completed Terminated Completed
2 Completed Abandoned terminated
2 Completed Completed Terminated
2 Completed Terminated Abandoned
would brake down to
Acc Stage 1 Stage 2 Stage 3
1 Completed Completed Completed
2 Completed Completed Terminated
Sorry, don't think I've explained it partically well. Let me know your thoughts.
Solved! Go to Solution.
@Anonymous
Try this.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXLOzy3ISS1JTQGyHZMS81Ly88DskNSi3My8RJBErA6mUmQ2AaVI0sgSIKVGxDsAXSkeB6ArRXEAworYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Acc = _t, #"Stage 1" = _t, #"Stage 2" = _t, #"Stage 3" = _t]), mytable = #table({"Stage","Priority"},{{"Completed",1},{"Terminated",2},{"Abandoned",3}}), ChangedType = Table.TransformColumnTypes(Source,{{"Acc", Int64.Type}, {"Stage 1", type text}, {"Stage 2", type text}, {"Stage 3", type text}}), #"Unpivoted Columns" = Table.UnpivotOtherColumns(ChangedType, {"Acc"}, "Attribute", "Value"), #"Merged Queries" = Table.NestedJoin(#"Unpivoted Columns",{"Value"},mytable,{"Stage"},"Unpivoted Columns",JoinKind.LeftOuter), #"Expanded Unpivoted Columns" = Table.ExpandTableColumn(#"Merged Queries", "Unpivoted Columns", {"Priority"}, {"Priority"}), #"Grouped Rows" = Table.Group(#"Expanded Unpivoted Columns", {"Acc", "Attribute"}, {{"Priority", each List.Min([Priority]), type number}}), Custom1 = Table.NestedJoin(#"Grouped Rows",{"Priority"},mytable,{"Priority"},"Unpivoted Columns",JoinKind.LeftOuter), #"Expanded Unpivoted Columns1" = Table.ExpandTableColumn(Custom1, "Unpivoted Columns", {"Stage"}, {"Stage"}), #"Removed Columns" = Table.RemoveColumns(#"Expanded Unpivoted Columns1",{"Priority"}), #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Attribute]), "Attribute", "Stage") in #"Pivoted Column"
@Anonymous
Try this.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXLOzy3ISS1JTQGyHZMS81Ly88DskNSi3My8RJBErA6mUmQ2AaVI0sgSIKVGxDsAXSkeB6ArRXEAworYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Acc = _t, #"Stage 1" = _t, #"Stage 2" = _t, #"Stage 3" = _t]), mytable = #table({"Stage","Priority"},{{"Completed",1},{"Terminated",2},{"Abandoned",3}}), ChangedType = Table.TransformColumnTypes(Source,{{"Acc", Int64.Type}, {"Stage 1", type text}, {"Stage 2", type text}, {"Stage 3", type text}}), #"Unpivoted Columns" = Table.UnpivotOtherColumns(ChangedType, {"Acc"}, "Attribute", "Value"), #"Merged Queries" = Table.NestedJoin(#"Unpivoted Columns",{"Value"},mytable,{"Stage"},"Unpivoted Columns",JoinKind.LeftOuter), #"Expanded Unpivoted Columns" = Table.ExpandTableColumn(#"Merged Queries", "Unpivoted Columns", {"Priority"}, {"Priority"}), #"Grouped Rows" = Table.Group(#"Expanded Unpivoted Columns", {"Acc", "Attribute"}, {{"Priority", each List.Min([Priority]), type number}}), Custom1 = Table.NestedJoin(#"Grouped Rows",{"Priority"},mytable,{"Priority"},"Unpivoted Columns",JoinKind.LeftOuter), #"Expanded Unpivoted Columns1" = Table.ExpandTableColumn(Custom1, "Unpivoted Columns", {"Stage"}, {"Stage"}), #"Removed Columns" = Table.RemoveColumns(#"Expanded Unpivoted Columns1",{"Priority"}), #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Attribute]), "Attribute", "Stage") in #"Pivoted Column"
@Anonymous
See file attached as well
Actually within the query we create a small table assigning priority to each stage value
Hey Zubair Muhammad,
Sorry to be a pain, I'm very early on with MSBI still. Where do I paste the code into?
HI @Anonymous
Please make a backup of your pbix file first.
Then copy paste the code as follows
Hey Zubair Muhammad,
The code you sent me seems to be along the right lines however it's sourcing the data from the example table on this thread. When I change the peramitors various errors arrive.
Would it be eaiser if I link you to the excel sheet I'm sourcing the data from? I've created a download directory below if that's any help. Alternativly, happy to email it over?
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
124 | |
79 | |
50 | |
38 | |
38 |
User | Count |
---|---|
195 | |
80 | |
70 | |
51 | |
42 |