Power Query - Change data

Reuven Leibowitz 41 Reputation points
2020-12-03T10:28:19.217+00:00

Dear

I'm getting data into Power query with some dates and I need to change the dates for all rows to the current date.

I can't use Table.ReplaceValue, because it requires to type the old value explicitly, but the old date is not constant.

What's the correct function to use?

Note, I can't add a custom column, but rather I must change the existing date

Thank you

Reuven

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
42,603 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Lz._ 9,011 Reputation points
    2020-12-03T11:06:16.88+00:00

    Hi @Reuven Leibowitz

    let  
        // Source table for demo:  
        Source = Table.FromList(  
            List.Dates(#date(2020,1,1),10,#duration(1,0,0,0)),  
            Splitter.SplitByNothing(),  
            type table [ColumnWithDates=date]  
        ),  
        AllDatesAsToday = Table.TransformColumns(Source,  
            {"ColumnWithDates", each Date.From(DateTime.LocalNow()), type date}  
        )  
    in  
        AllDatesAsToday  
    

    EDIT: I did not mention the following option as it doesn't allow keeping the types (with same Source as above):

         AllDatesAsToday = Table.ReplaceValue(Source, each [ColumnWithDates], each  
            Date.From(DateTime.LocalNow()),  
            Replacer.ReplaceValue, {"ColumnWithDates"}  
         )  
    

    If this solves your problem please mark as answer to help others with a similar scenario - Thanks

    0 comments No comments

  2. Reuven Leibowitz 41 Reputation points
    2020-12-04T09:23:59.857+00:00

    Hi Lz
    Your second answer is more focused on my question, as my Achilles' heel is using each and _ .
    I must point out that it's very beneficiary to read your codes. I'm learning a lot from it.
    If you are giving a web course I would like to join it.

    Thanks
    Reuven


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.