Forum Discussion
calculate with date
- Anonymous2 years ago
Hi Nelleke-NL
You can create a custom cloumn and input the following code
=if [Einddatum]<>null then Number.Round(Number.From(([Einddatum] -[Startdatum])/( 365.25 / 12 )),0) else Number.Round(Number.From((DateTime.Date(DateTime.LocalNow()) -[Startdatum])/( 365.25 / 12 )),0)Output
and you can create a blank query and put the whole code in advanced editor in power query
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fZNJjsQgDEWv0mIdJGxCgLNEdf9rtIcQPqirF5E8vHj4wH2HGilyYg5HIPnA7W7m8DnuUGZcP3DFcFMx4pnImgSf+rB38txITvEEMs9MURJnOWMD8pyZayO37kBWzYJPVyyT5Bov8Ui3adoRfOmuc1J3MoF2mqUvIi2J9C+JY5F3nLtfuBHjrmtajiLWeZQLmTeSOWYo2gDVU8KAzFL+VpTKJinXRXzpZ24ytV3yGdEdH8foIYhgFQU6ws/obLdF9aHmnd8A56cYOVt9PWO7lYTAa+NCNlKChVb7Qd+ZvBIExAZFqQFqaQj0r2TeSBGsAkrjvah6dldmYNp2ohmqFhcIArFD1TGN3hB9peAn/0ku1OcX", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Gemaakt op" = _t, Dossiernummer = _t, Startdatum = _t, Einddatum = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Gemaakt op", type text}, {"Dossiernummer", Int64.Type}, {"Startdatum", type text}, {"Einddatum", type text}}), #"Changed Type with Locale" = Table.TransformColumnTypes(#"Changed Type", {{"Gemaakt op", type date}, {"Startdatum", type date}, {"Einddatum", type date}}, "en-GB"), #"Added Custom" = Table.AddColumn(#"Changed Type with Locale", "Custom", each if [Einddatum]<>null then Number.Round(Number.From(([Einddatum] -[Startdatum])/( 365.25 / 12 )),0) else Number.Round(Number.From((DateTime.Date(DateTime.LocalNow()) -[Startdatum])/( 365.25 / 12 )),0)) in #"Added Custom"Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
No is not working. sorry for language
My language is dutch I get a yellow meassge error in IF name
I have the version Power BI on desktop, no licences
| Gemaakt op | Dossiernummer | Startdatum | Einddatum |
| 7-1-2022 | 1 | 7-1-2022 | 9-1-2023 |
| 5-1-2022 | 2 | 5-1-2022 | 1-2-2022 |
| 12-1-2022 | 3 | 12-1-2022 | 19-1-2022 |
| 12-1-2022 | 4 | 12-1-2022 | 20-4-2022 |
| 13-1-2022 | 5 | 15-1-2022 | 24-8-2022 |
| 14-1-2022 | 6 | 15-1-2022 | 19-1-2022 |
| 14-1-2022 | 7 | 14-1-2022 | 16-5-2022 |
| 27-6-2013 | 8 | 27-6-2013 | 24-4-2019 |
| 20-1-2022 | 9 | 21-1-2022 | 1-2-2022 |
| 21-1-2022 | 10 | 21-1-2022 | 1-2-2022 |
| 24-1-2022 | 11 | 24-1-2022 | 26-1-2022 |
| 25-1-2022 | 12 | 26-1-2022 | 3-7-2023 |
| 25-1-2022 | 13 | 26-1-2022 | 22-3-2022 |
| 28-1-2022 | 14 | 28-1-2022 | 24-5-2022 |
| 14-1-2022 | 15 | 14-1-2022 | 27-1-2022 |
| 16-11-2020 | 16 | 16-11-2020 | 24-11-2020 |
| 1-2-2022 | 17 | 1-2-2022 | |
| 14-4-2021 | 18 | 14-4-2021 | 23-11-2021 |
| 17-3-2021 | 19 | 17-3-2021 | 17-3-2021 |
| 14-1-2020 | 20 | 14-1-2020 | 14-1-2020 |
| 14-2-2022 | 21 | 14-2-2022 | 14-3-2022 |
| 18-2-2022 | 22 | 18-2-2022 | 9-3-2022 |
| 18-2-2022 | 23 | 18-2-2022 | 16-7-2022 |
| 11-4-2022 | 24 | 11-4-2022 | 11-4-2022 |
| 23-2-2022 | 25 | 23-2-2022 | 25-9-2022 |
| 1-3-2022 | 26 | 4-3-2022 | 20-2-2023 |
Hi Nelleke-NL
You can create a custom cloumn and input the following code
=if [Einddatum]<>null then Number.Round(Number.From(([Einddatum] -[Startdatum])/( 365.25 / 12 )),0) else Number.Round(Number.From((DateTime.Date(DateTime.LocalNow()) -[Startdatum])/( 365.25 / 12 )),0)
Output
and you can create a blank query and put the whole code in advanced editor in power query
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fZNJjsQgDEWv0mIdJGxCgLNEdf9rtIcQPqirF5E8vHj4wH2HGilyYg5HIPnA7W7m8DnuUGZcP3DFcFMx4pnImgSf+rB38txITvEEMs9MURJnOWMD8pyZayO37kBWzYJPVyyT5Bov8Ui3adoRfOmuc1J3MoF2mqUvIi2J9C+JY5F3nLtfuBHjrmtajiLWeZQLmTeSOWYo2gDVU8KAzFL+VpTKJinXRXzpZ24ytV3yGdEdH8foIYhgFQU6ws/obLdF9aHmnd8A56cYOVt9PWO7lYTAa+NCNlKChVb7Qd+ZvBIExAZFqQFqaQj0r2TeSBGsAkrjvah6dldmYNp2ohmqFhcIArFD1TGN3hB9peAn/0ku1OcX", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Gemaakt op" = _t, Dossiernummer = _t, Startdatum = _t, Einddatum = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Gemaakt op", type text}, {"Dossiernummer", Int64.Type}, {"Startdatum", type text}, {"Einddatum", type text}}),
#"Changed Type with Locale" = Table.TransformColumnTypes(#"Changed Type", {{"Gemaakt op", type date}, {"Startdatum", type date}, {"Einddatum", type date}}, "en-GB"),
#"Added Custom" = Table.AddColumn(#"Changed Type with Locale", "Custom", each if [Einddatum]<>null then Number.Round(Number.From(([Einddatum] -[Startdatum])/( 365.25 / 12 )),0) else Number.Round(Number.From((DateTime.Date(DateTime.LocalNow()) -[Startdatum])/( 365.25 / 12 )),0))
in
#"Added Custom"
Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Nelleke-NL2 years agoHelper II
Great! It works. I'm happy so happy. Thats gives us a lot more information. Thanks💐
- Nelleke-NL2 years agoHelper II
I hardly dare to ask...
December 31 is always a reference date. How can I use that date for separate column?Replace DateTime.LocalNow() with (Date(12/31/2023))
I can now only find these figures on January 1, while it may only be later that I retrieve this data.
I will then have to adjust the year each time. Do you have another solution for me?