Skip to content

Instantly share code, notes, and snippets.

@ImkeF
Last active November 18, 2019 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ImkeF/1dfcac25caa1fb5ec2af831fec8b15bb to your computer and use it in GitHub Desktop.
Save ImkeF/1dfcac25caa1fb5ec2af831fec8b15bb to your computer and use it in GitHub Desktop.
let func =
(ExpandedJson as table, optional adjustDotDel as number) =>
let
AdjustSkip = if adjustDotDel = null then 1 else adjustDotDel,
Source = ExpandedJson,
NameKey = Table.AddColumn(Source, "NameKey", each Text.Combine(List.Transform([Dots], (x) => Text.From(Record.Field(_,x))), " | "), type text),
Item = Table.AddColumn(NameKey, "Item", each Text.BeforeDelimiter([Sort], ".", {0, RelativePosition.FromEnd}), type text),
#"Extracted Text After Delimiter" = Table.TransformColumns(Item, {{"SortBy", each Text.BeforeDelimiter(_, ".", AdjustSkip), type text}}),
#"Removed Other Columns" = Table.SelectColumns(#"Extracted Text After Delimiter",{"Value", "NameKey", "Item", "SortBy"}),
#"Pivoted Column" = Table.Pivot(#"Removed Other Columns", List.Distinct(#"Removed Other Columns"[NameKey]), "NameKey", "Value")
in
#"Pivoted Column" ,
documentation = [
Documentation.Name = " Table.FlattenJSON ",
Documentation.Description = " Flattens expanded JSON table ",
Documentation.LongDescription = " Flattens expanded JSON table ",
Documentation.Category = " Table ",
Documentation.Source = " www.TheBIccountant.com ",
Documentation.Version = " 1.0 ",
Documentation.Author = " Imke Feldmann: www.TheBIccountant.com. . ",
Documentation.Examples = {[Description = " ",
Code = " ",
Result = " "]}]
in
Value.ReplaceType(func, Value.ReplaceMetadata(Value.Type(func), documentation))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment