Forum Discussion
ch_metglobal
1 year agoNew Member
Converting quarter data into months
Hi all-- I thought I was able to easily perform this transformation but realized the dates make it a bit more complicated for me. I have the following dataset where I need to convert into monthl...
- 1 year ago
Hi ch_metglobal
With "Your_Source"
Column1 YYYYQN Value a 2025Q1 93 a 2025Q2 10 a 2025Q3 58 a 2025Q4 60 b 2025Q1 90 b 2025Q2 45 b 2025Q3 80 b 2025Q4 107 let
Source = Your_Source,
Transform = Table.TransformColumns(Source,
{{"YYYYQN", (x) => List.Transform({1, 2, 3},
each #date(Number.From(Text.Start(x,4)), (Number.From(Text.End(x,1))-1)*3+_, 15)), type list},
{"Value", each _ /3, type number}}),
Expand = Table.ExpandListColumn(Transform, "YYYYQN")
in
ExpandStéphane
- 1 year ago
Given your data:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUTIyMDINNAQyLI2VYnWQxIyADEMDVDFjIMPUAlXMBMgwg6hLQjEPTQxknokpqhjIPAs0dSZge82VYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Quarter = _t, Amount = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Quarter", type text}, {"Amount", Int64.Type}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"Column1","Quarter"}, { {"Monthly", (t)=> [a=List.Sum(t[Amount]) / 3, b=#date(Number.From(Text.Start(t[Quarter]{0},4)), (Number.From(Text.End(t[Quarter]{0},1))-1)*3+1,15 ), c=List.Accumulate({0..2},{},(s,c)=> s & {Date.AddMonths(b,c)}), d=List.Transform(List.Zip({c, List.Repeat({a},3)}), each Record.FromList(_,{"Date","Amount"})) ][d], type {[Date=date, Amount=number]} }}), #"Expanded Monthly" = Table.ExpandListColumn(#"Grouped Rows", "Monthly"), #"Removed Columns" = Table.RemoveColumns(#"Expanded Monthly",{"Quarter"}), #"Expanded Monthly1" = Table.ExpandRecordColumn(#"Removed Columns", "Monthly", {"Date", "Amount"}) in #"Expanded Monthly1"Produces:
- 1 year ago
NewStep=#table(Table.ColumnNames(YourSourceName),List.TransfromMany(Table.ToRows(YourSourceName),each let a=Text.Split(_{1},"Q") in List.Transform({1..3},each #date(Number.From(a{0}),Number.From(a{1})*3-3+_,15)),(x,y)=>{x{0},y,x{2}/3}))
wdx223_Daniel
1 year agoCommunity Champion
NewStep=#table(Table.ColumnNames(YourSourceName),List.TransfromMany(Table.ToRows(YourSourceName),each let a=Text.Split(_{1},"Q") in List.Transform({1..3},each #date(Number.From(a{0}),Number.From(a{1})*3-3+_,15)),(x,y)=>{x{0},y,x{2}/3}))