Forum Discussion
Multiple date formats in column
- 4 years ago
Leave everything, in a custom column put this. That's it.
= Date.From(if Text.Contains(Text.From([Live date]),"'") then "1"&Text.Replace([Live date],"'","") else [Live date])If you want to convert this column to a date, select column - Transform tab - Detect data type
1. Make sure [Date] is replaced with your column name.
2. Ideal will be to upload the file without confidential/sensitive data to a cloud storage service such as Onedrive/Google Drive/Dropbox/Box (Onedrive preferred) and share the link here.
3. For Blank query - Right click on left side pane - New Query - Blank Query
1. My Field name is 'Live date' so my new column looks like this..
Date.From(if Text.Contains([Live date],"'") then "1"&Text.Replace([Live date],"'","") else[Live date])
2. The [Live date] is currently a text field.
3. The New field is also a text field - the "replace" part in the script above works...(although it is still Text format..
4. However the dates that were (correct) dates before, produce the error.
I suspect it might be a Data type error?
- Vijay_A_Verma4 years agoMost Valuable Professional
Can you click on one of the errors and post the error here? To have the column in date format, use below step (Replace Source with your previous step)
= Table.AddColumn(Source, "Custom", each Date.From(if Text.Contains([Live date],"'") then "1"&Text.Replace([Live date],"'","") else[Live date]), type date)OR you can select the Custom column - Transform menu - Detect data type
- lornafnb4 years agoHelper I
I'm so sorry - I am really stupid with this.
1. The error message that the values cannot be converted to text - so your thinking that it needs to be converted to date is correct.
2. In your suggestion - it starts with Table.Addcolumn....why is that - I still have a query, not a table...
thanks
- lornafnb4 years agoHelper I
I'm somewhat confused.
The order that I add the column is:
1) Transform
2) Add Column - Customer Column
3) I paste your line of code in there - get the below...(Then you mention I should replace Source with my previous step - I dont understand.)
4. If I expand the Custom column, I get this...
Then I select the Date Effective field only and I get an Error...
All the Steps I have taken up to here is
I dont know where I am going wrong
Thanks
- Vijay_A_Verma4 years agoMost Valuable Professional
Do following -
1. Paste your sample data as table here. Refer to this - How to provide sample data in the Power BI Forum - https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
2. Go to advanced editor, copy the code, in this text box press </> above, paste the code
Press Reply.