Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Need help with this power query

Input data 

 

kkoc3_2-1639436099970.png

 

 

 

Expected output 

 

kkoc3_3-1639436115812.png

 

Sample data 

 

IDDate/Time (UTC)UserDescriptionSecurity ChangePrevious Value
215790215/11/2021 5:31Testuser@test.comBegin sync revision  
215790315/11/2021 5:31Testuser@test.comChange Line Item  
215790315/11/2021 5:31Testuser@test.comChange Line Item  
215790315/11/2021 5:31Testuser@test.comChange Line Item  
215790315/11/2021 5:31Testuser@test.comChange Line Item  
215790315/11/2021 5:31Testuser@test.comChange Line Item  
215790315/11/2021 5:31Testuser@test.comChange Line Item  
 15/11/2021 5:31Testuser@test.comRevision Synced 20211115_01
215790615/11/2021 5:31Testuser@test.comSync revision completed  
215790815/11/2021 5:39Testuser@test.comImport  
215790915/11/2021 5:39Testuser@test.comItem Included in Subset  
215790915/11/2021 5:39Testuser@test.comItem Removed from Subset  
215790915/11/2021 5:39Testuser@test.comItem Removed from Subset  
215790915/11/2021 5:39Testuser@test.comItem Removed from Subset  
215790915/11/2021 5:39Testuser@test.comItem Removed from Subset  
215790915/11/2021 5:39Testuser@test.comItem Removed from Subset  
215790915/11/2021 5:39Testuser@test.comItem Removed from Subset  
215790915/11/2021 5:39Testuser@test.comItem Removed from Subset  
215790915/11/2021 5:39Testuser@test.comItem Removed from Subset  
215790915/11/2021 5:39Testuser@test.comItem Removed from Subset  
215790915/11/2021 5:39Testuser@test.comItem Removed from Subset  
215790915/11/2021 5:39Testuser@test.comItem Removed from Subset  
215795615/11/2021 22:49Testuser@test.comBegin sync revision 20211116_01
215795715/11/2021 22:49Testuser@test.comChange Line Item  
215795715/11/2021 22:49Testuser@test.comChange Line Item  
215795715/11/2021 22:49Testuser@test.comChange Line Item  
215795715/11/2021 22:49Testuser@test.comChange Import  
215795815/11/2021 22:49Testuser@test.comChange Line Item  
215795815/11/2021 22:49Testuser@test.comChange Line Item  
215795815/11/2021 22:49Testuser@test.comChange Line Item  
215795815/11/2021 22:49Testuser@test.comChange Line Item  
215795915/11/2021 22:49Testuser@test.comChange Line Item  
215795915/11/2021 22:49Testuser@test.comChange Line Item  
 15/11/2021 22:49Testuser@test.comRevision Synced  
215796015/11/2021 22:49Testuser@test.comSync revision completed  

 

1 ACCEPTED SOLUTION
Jakinta
Solution Sage
Solution Sage

There should be more elegant solution, but until somebody provides it, you can try this

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("7dZNi8IwEAbgvzL0LNrETbWeRE+FPVlvIou2s92CSaRJhf33O0pd6kcxBxHRFgplIA/TMnmbxcLjTAxCn3sdj4keYz3ucwZi1GdUmaOxpcFibOmhm2hJtQlmuQLzqxIocJebXCuqwuFedo5e39mb/qxUhvCZK4TIomyxZ8LAmZlVwwAxjQamlbJfRZf48lmtucBZjetzBlTbbtD+6/UXHl6YYYMZya0u7BUidCfoO0Gkkk2ZYgq0H+JybfAO5gyl3hH5XWjZoi3aog9BxVkicT76aFKbf4BV2AUnYScG7vTtXH8xrSmKxfCujb2PFj6lBu7O9WNEranAd8dunh6Wfw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Date/Time (UTC)" = _t, User = _t, Description = _t, #"Security Change" = _t, #"Previous Value" = _t]),
    Custom1 = List.Transform(Source[Description], each if Text.Contains(_, "sync revision", Comparer.OrdinalIgnoreCase) then "x" else null),
    Custom2 = List.Transform ( List.Split( List.PositionOf( Custom1, "x", Occurrence.All), 2), each List.Repeat({"x"},_{1}-_{0}+1)),
    Custom3 = List.Transform ( List.Split( List.RemoveLastN(List.RemoveFirstN(List.PositionOf( Custom1, "x", Occurrence.All), 1),1), 2), each List.Repeat({"y"},_{1}-_{0}-1)),
    HelperColumn = List.Accumulate ( List.RemoveNulls(List.Union(List.Zip({Custom2,Custom3})) ), {}, (s,c)=> s&c ),
    NewTable = Table.FromColumns( Table.ToColumns(Source) & {HelperColumn}  , Table.ColumnNames(Source)&{"Helper"}),
    Grouped = Table.Group(NewTable, {"Helper"}, {{"A", each let t=_ in Table.AddColumn ( Table.AddColumn(_, "Type Of Change", each if [Helper]="x" then "Part of Sync" else "Non Revision sync" ), "Sync ID", each List.Max (t[#"Previous Value"])), type table}}, GroupKind.Local),
    #"Expanded A" = Table.ExpandTableColumn(Grouped, "A", Table.ColumnNames(Source)&{"Type Of Change", "Sync ID"}),
    FINAL = Table.RemoveColumns(#"Expanded A",{"Helper"})
in
    FINAL

View solution in original post

2 REPLIES 2
CNENFRNL
Community Champion
Community Champion

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("7dZNi8IwEAbgvzL0LNrETbWeRE+FPVlvIou2s92CSaRJhf33O0pd6kcxBxHRFgplIA/TMnmbxcLjTAxCn3sdj4keYz3ucwZi1GdUmaOxpcFibOmhm2hJtQlmuQLzqxIocJebXCuqwuFedo5e39mb/qxUhvCZK4TIomyxZ8LAmZlVwwAxjQamlbJfRZf48lmtucBZjetzBlTbbtD+6/UXHl6YYYMZya0u7BUidCfoO0Gkkk2ZYgq0H+JybfAO5gyl3hH5XWjZoi3aog9BxVkicT76aFKbf4BV2AUnYScG7vTtXH8xrSmKxfCujb2PFj6lBu7O9WNEranAd8dunh6Wfw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Date/Time (UTC)" = _t, User = _t, Description = _t, #"Security Change" = _t, #"Previous Value" = _t]),

    Grouped = Table.Group(Source, "Description", {"grp", each let idxed = Table.AddIndexColumn(_, "Index", 0,1), id = List.Select([Previous Value], each Text.Trim(_)<>""){0}, completion = List.PositionOf([Description], "Sync revision completed") in Table.AddColumn(idxed, "status", each if [Index] <= completion then "Part of Sync|"&id else "Non Revision sync")}, 0, (x,y) => Byte.From(y="Begin sync revision")),
    #"Expanded grp" = Table.ExpandTableColumn(Table.RemoveColumns(Grouped, "Description"), "grp", {"ID", "Date/Time (UTC)", "User", "Description", "Security Change", "Previous Value", "status"}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Expanded grp", "status", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), {"Type", "Sync id"})
in
    #"Split Column by Delimiter"

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Jakinta
Solution Sage
Solution Sage

There should be more elegant solution, but until somebody provides it, you can try this

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("7dZNi8IwEAbgvzL0LNrETbWeRE+FPVlvIou2s92CSaRJhf33O0pd6kcxBxHRFgplIA/TMnmbxcLjTAxCn3sdj4keYz3ucwZi1GdUmaOxpcFibOmhm2hJtQlmuQLzqxIocJebXCuqwuFedo5e39mb/qxUhvCZK4TIomyxZ8LAmZlVwwAxjQamlbJfRZf48lmtucBZjetzBlTbbtD+6/UXHl6YYYMZya0u7BUidCfoO0Gkkk2ZYgq0H+JybfAO5gyl3hH5XWjZoi3aog9BxVkicT76aFKbf4BV2AUnYScG7vTtXH8xrSmKxfCujb2PFj6lBu7O9WNEranAd8dunh6Wfw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Date/Time (UTC)" = _t, User = _t, Description = _t, #"Security Change" = _t, #"Previous Value" = _t]),
    Custom1 = List.Transform(Source[Description], each if Text.Contains(_, "sync revision", Comparer.OrdinalIgnoreCase) then "x" else null),
    Custom2 = List.Transform ( List.Split( List.PositionOf( Custom1, "x", Occurrence.All), 2), each List.Repeat({"x"},_{1}-_{0}+1)),
    Custom3 = List.Transform ( List.Split( List.RemoveLastN(List.RemoveFirstN(List.PositionOf( Custom1, "x", Occurrence.All), 1),1), 2), each List.Repeat({"y"},_{1}-_{0}-1)),
    HelperColumn = List.Accumulate ( List.RemoveNulls(List.Union(List.Zip({Custom2,Custom3})) ), {}, (s,c)=> s&c ),
    NewTable = Table.FromColumns( Table.ToColumns(Source) & {HelperColumn}  , Table.ColumnNames(Source)&{"Helper"}),
    Grouped = Table.Group(NewTable, {"Helper"}, {{"A", each let t=_ in Table.AddColumn ( Table.AddColumn(_, "Type Of Change", each if [Helper]="x" then "Part of Sync" else "Non Revision sync" ), "Sync ID", each List.Max (t[#"Previous Value"])), type table}}, GroupKind.Local),
    #"Expanded A" = Table.ExpandTableColumn(Grouped, "A", Table.ColumnNames(Source)&{"Type Of Change", "Sync ID"}),
    FINAL = Table.RemoveColumns(#"Expanded A",{"Helper"})
in
    FINAL

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.