Forum

Adding a column wit...
 
Notifications
Clear all

Adding a column with dynamic function: date Today

5 Posts
3 Users
0 Reactions
67 Views
(@a-vanlieshout64gmail-com)
Posts: 6
Active Member
Topic starter
 

Hi Mynda,

I want to add a column in Power Query which gives the date of Today in every line (like in Excel =VANDAAG() . The formula must be dynamic.

Can you tell me how to do this?

Thx

 
Posted : 30/05/2023 11:06 am
Riny van Eekelen
(@riny)
Posts: 1186
Member Moderator
 

That would be:

DateTime.LocalNow()

And then set the column data type to Date. That does what TODAY() does in Excel.

 
Posted : 30/05/2023 11:51 am
(@a-vanlieshout64gmail-com)
Posts: 6
Active Member
Topic starter
 

Hi Riny, Thanks for your answer. I made the following steps:

1. Add a custom column, which is a copy of a date column that was already there. I named the column DateTime. I changed the type of this column into  date

2. Power Query automatically generates the following M-text

= Table.TransformColumnTypes(#"Aangepaste kolom toegevoegd",{{"DateTime", type date}})

3. Then I tried to change the text      type date       into        type datetime.localnow

= Table.TransformColumnTypes(#"Aangepaste kolom toegevoegd",{{"DateTime", type DateTime.LocalNow}})

But unfortunately I get an error. What am I doing wrong?

 
Posted : 17/06/2023 9:38 am
(@a-vanlieshout64gmail-com)
Posts: 6
Active Member
Topic starter
 

In addition to my last answer:

My Power Query does not recognize the type     DateTime.LocalNow    (although it is shown when I start typing)

It does however recognize the type    datetime      (see underneath, this type is accepted, but it is not the type I want.

= Table.AddColumn(#"Type gewijzigd", "Vandaag", each [Datum], type datetime)

 

The error = Type ID is not valid

 
Posted : 17/06/2023 12:03 pm
(@mynda)
Posts: 4761
Member Admin
 

Hi Antonia,

Try just using the data type drop down on the column to apply the Date Time data type. This should apply it using the nomenclature for your locale.

Mynda

 
Posted : 17/06/2023 7:23 pm
Share: