Forum Discussion
Syndicate_Admin
3 years agoAdministrator
Streamline log table
Good morning I have a data record in a SQL database, which is saved as follows: Date Type Value 23/11/2022 14:26 Registration 3984XXX 23/11/2022 14:26 Loading area A 23/11/...
v-jianboli-msft
3 years agoCommunity Support
Hi Syndicate_Admin ,
Please try:
Change the day to date type - create an index column for every four rows -pivot your data
Here is the M code:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jdBNC4IwHMfxtyI7C7r/HpzdrG5Jh4hQxMPAYQPTsFn07puXipjmafzYl/FhRYG20ijko+PzOh4n2QwKlX6BgAQYBxACeJiugNvLg6r1zfTS6K61k8SCZlk2VaedrHRbe7JX0s5krlOV91C6Phu7GeDQ1Uaf9t41w2XkRiycbH+0wDjL83zu5S/t+o/grSVcLNbS5VpCGd+l+4XajauLHVrO3H8bO7RCRAyV5Qs=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}}),
#"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
#"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Date", type text}, {"Type", type text}, {"Value", type text}}),
#"Changed Type with Locale" = Table.TransformColumnTypes(#"Changed Type1", {{"Date", type datetime}}, "en-GB"),
#"Added Custom1" = Table.AddIndexColumn(#"Changed Type with Locale","Index",1,1),
#"Added Custom" = Table.AddColumn(#"Added Custom1", "Custom", each Number.RoundUp([Index]/4)),
#"Changed Type2" = Table.TransformColumnTypes(#"Added Custom",{{"Date", type date}}),
#"Removed Other Columns" = Table.SelectColumns(#"Changed Type2",{"Type", "Date", "Value"}),
#"Added Index" = Table.AddIndexColumn(#"Removed Other Columns", "Index", 1, 1, Int64.Type),
#"Added Custom2" = Table.AddColumn(#"Added Index", "Custom", each Number.RoundUp([Index]/4)),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom2",{"Index"}),
#"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Type]), "Type", "Value"),
#"Removed Columns1" = Table.RemoveColumns(#"Pivoted Column",{"Custom"})
in
#"Removed Columns1"
Final output:
Best Regards,
Jianbo Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Syndicate_Admin
3 years agoAdministrator
Thank you very much for your very detailed answer.
I have an extra problem: not all records are correct, there are incomplete orders that do not have the 4 data, and there are some that are not in that order.
Would you have a solution?
Thanks a lot