Forum Discussion
OTD_column
- 4 years ago
Hi Anonymous ,
Try this slightly updated code:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XY3LDcAgDEN3yRmJ2HxKZ0Hdf42SAhLpxZLznpzeBVdjuiUI1KJEaKTSijzh5LTTofDH0+LV84KMbPcvWgQMYhXO4s0y32iaM654s46gRsU2uTeH+bw=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [OF = _t, phase = _t, Dt_fin = _t, Dt_fin_prev = _t]), chgTypes = Table.TransformColumnTypes(Source,{{"Dt_fin", type date}, {"Dt_fin_prev", type date}}), addIndex = Table.AddIndexColumn(chgTypes, "Index", 0, 1, Int64.Type), addOtdTemp = Table.Buffer(Table.AddColumn(addIndex, "OTDTemp", each if [Dt_fin_prev]=null then "" else if [Dt_fin_prev]>=Date.From(DateTime.LocalNow()) then 1 else if [Dt_fin]<=[Dt_fin_prev] then 1 else 0)), addOtd = Table.AddColumn(addOtdTemp, "OTD", each try if [Dt_fin]=null and addOtdTemp[Dt_fin]{[Index]-1}=null and [OF]=addOtdTemp[OF]{[Index]-1} then addOtdTemp[OTDTemp]{[Index]-1} else [OTDTemp] otherwise ""), remCols = Table.RemoveColumns(addOtd,{"Index", "OTDTemp"}) in remColsThe last code should have sped up your query a lot, but may not have removed the multi-load requirement. I'm hoping this version will speed it up a bit more and also *should* remove the multi-load requirement. Even if it doesn't, it should only load twice maximum now.
Pete
What is the source of your data?
the source is SQL server data warehouse
- BA_Pete4 years agoSuper User
Hi Anonymous ,
Can you try this slightly amended code please?
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XY3LDcAgDEN3yRmJ2HxKZ0Hdf42SAhLpxZLznpzeBVdjuiUI1KJEaKTSijzh5LTTofDH0+LV84KMbPcvWgQMYhXO4s0y32iaM654s46gRsU2uTeH+bw=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [OF = _t, phase = _t, Dt_fin = _t, Dt_fin_prev = _t]), chgTypes = Table.TransformColumnTypes(Source,{{"Dt_fin", type date}, {"Dt_fin_prev", type date}}), addIndex = Table.AddIndexColumn(chgTypes, "Index", 0, 1, Int64.Type), addOtdTemp = Table.AddColumn(addIndex, "OTDTemp", each if [Dt_fin_prev]=null then "" else if [Dt_fin_prev]>=Date.From(DateTime.LocalNow()) then 1 else if [Dt_fin]<=[Dt_fin_prev] then 1 else 0), bufOtdTemp = Table.Buffer(addOtdTemp), addOtd = Table.AddColumn(addOtdTemp, "OTD", each try if [Dt_fin]=null and bufOtdTemp[Dt_fin]{[Index]-1}=null and [OF]=bufOtdTemp[OF]{[Index]-1} then bufOtdTemp[OTDTemp]{[Index]-1} else [OTDTemp] otherwise ""), remCols = Table.RemoveColumns(addOtd,{"Index", "OTDTemp"}) in remColsPete
- Anonymous4 years agoNot applicable
hi BA_Pete
it doesn't work
- BA_Pete4 years agoSuper User
Hi Anonymous ,
Try this slightly updated code:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XY3LDcAgDEN3yRmJ2HxKZ0Hdf42SAhLpxZLznpzeBVdjuiUI1KJEaKTSijzh5LTTofDH0+LV84KMbPcvWgQMYhXO4s0y32iaM654s46gRsU2uTeH+bw=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [OF = _t, phase = _t, Dt_fin = _t, Dt_fin_prev = _t]), chgTypes = Table.TransformColumnTypes(Source,{{"Dt_fin", type date}, {"Dt_fin_prev", type date}}), addIndex = Table.AddIndexColumn(chgTypes, "Index", 0, 1, Int64.Type), addOtdTemp = Table.Buffer(Table.AddColumn(addIndex, "OTDTemp", each if [Dt_fin_prev]=null then "" else if [Dt_fin_prev]>=Date.From(DateTime.LocalNow()) then 1 else if [Dt_fin]<=[Dt_fin_prev] then 1 else 0)), addOtd = Table.AddColumn(addOtdTemp, "OTD", each try if [Dt_fin]=null and addOtdTemp[Dt_fin]{[Index]-1}=null and [OF]=addOtdTemp[OF]{[Index]-1} then addOtdTemp[OTDTemp]{[Index]-1} else [OTDTemp] otherwise ""), remCols = Table.RemoveColumns(addOtd,{"Index", "OTDTemp"}) in remColsThe last code should have sped up your query a lot, but may not have removed the multi-load requirement. I'm hoping this version will speed it up a bit more and also *should* remove the multi-load requirement. Even if it doesn't, it should only load twice maximum now.
Pete