Forum Discussion
Nelleke-NL
2 years agoHelper II
Null value in date column
Hi I have two date column but in each one there is sometimes the value null. I need months between [startdatum] and [einddatum]. I have : = Table.AddColumn(Bron, "duur dossierbehandeling", ...
- 2 years ago
Hi Nelleke-NL, I'm not sure wether I understand your needs but try to check this and update with your needs.
IMPORTANT: For future requests, provide sample data as table so we can copy/paste. It is also important to provide expected result based on sample data!
Result
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XYzBDcAwCAN34R0JTJo2mQVl/zUagqqWvpDvbMwIlWWwilYqhIuBCLMYCVh2lOU8qIdju2j/yUjk2aMvF6QxJJHP1ZrW/v70bnPXXzdv", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Startdatum = _t, Einddatum = _t]), ChangedType = Table.TransformColumnTypes(Source,{{"Startdatum", type date}, {"Einddatum", type date}}, "nl-NL"), Ad_EinddatumUpdated = Table.AddColumn(ChangedType, "Einddatum Updated", each if [Einddatum] <> null then [Einddatum] else Date.From(DateTime.LocalNow()), type date), Ad_StartdatumUpdated = Table.AddColumn(Ad_EinddatumUpdated, "Startdatum Updated", each if [Startdatum] <> null then [Startdatum] else [Einddatum Updated], type text), Ad_Months = Table.AddColumn(Ad_StartdatumUpdated, "Months", each Duration.Days( ([Einddatum Updated] - [Startdatum Updated]) / (365.25 / 12) ) , Int64.Type) in Ad_Months
dufoq3
2 years agoCommunity Champion
Hi Nelleke-NL, I'm not sure wether I understand your needs but try to check this and update with your needs.
IMPORTANT: For future requests, provide sample data as table so we can copy/paste. It is also important to provide expected result based on sample data!
Result
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XYzBDcAwCAN34R0JTJo2mQVl/zUagqqWvpDvbMwIlWWwilYqhIuBCLMYCVh2lOU8qIdju2j/yUjk2aMvF6QxJJHP1ZrW/v70bnPXXzdv", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Startdatum = _t, Einddatum = _t]),
ChangedType = Table.TransformColumnTypes(Source,{{"Startdatum", type date}, {"Einddatum", type date}}, "nl-NL"),
Ad_EinddatumUpdated = Table.AddColumn(ChangedType, "Einddatum Updated", each if [Einddatum] <> null then [Einddatum] else Date.From(DateTime.LocalNow()), type date),
Ad_StartdatumUpdated = Table.AddColumn(Ad_EinddatumUpdated, "Startdatum Updated", each if [Startdatum] <> null then [Startdatum] else [Einddatum Updated], type text),
Ad_Months = Table.AddColumn(Ad_StartdatumUpdated, "Months", each
Duration.Days( ([Einddatum Updated] - [Startdatum Updated]) / (365.25 / 12) )
, Int64.Type)
in
Ad_Months