Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Calculated column to get Date Field from Text

I am having a month YYYY field in my table and it is a pure text data type field.

 

Example :- Jan 2021, Feb 2021, Mar 2021 etc., 

 

I need to create a calculated column to convert these data to 01/01/2021, 01/02/2021, 01/03/2021, etc.,

 

How can we do it ? Please help.

  • Anonymous 

    have you tried to change the date type to date in PQ?

     

    or change the date type in column tools

2 Replies

  • Anonymous 

    have you tried to change the date type to date in PQ?

     

    or change the date type in column tools

  • Anonymous 

    Give this a try.

    Month Date = 
    VAR _Year = INT ( RIGHT ( 'Table'[Month Field], 4) )
    VAR _Month = 
        SWITCH (
            LEFT('Table'[Month Field],3),
            "Jan",1,"Feb",2,"Mar",3,"Apr",4,"May",5,"Jun",6,"Jul",7,"Aug",8,"Sep",9,"Oct",10,"Nov",11,"Dec",12
        )
    RETURN DATE ( _Year, _Month, 1 )