Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Ashish_Mathur
Super User
Super User

Change the format of columns containing a particular word to a date format

Hi,

Let's say i have 10 columns (could be any number of columns) in a dataset.  A randon number of headings (I do not know the position of those columns) contain the word birthdate - so the heaidngs could be 1 Birthdate2 Birthdate, 3 Birthdate etc.  In which ever cells of the headings the word Birthdate is found, I'd like all entries under those columns to be formatted as Dates.

Please help.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
2 REPLIES 2
Washivale
Resolver V
Resolver V

Hi @Ashish_Mathur ,

 

Add Python script to power query as below:

 

import pandas as pd
for col in dataset.columns:
if col.find("Birthday") ==-1:
pass
else:
dataset[col] = pd.to_datetime(dataset[col], errors='coerce')

 

it should return a table with changed datatype.

 

Thank You,

Washivale

Hi,

Thank you for replying.  Is there a way of doing this in the M language?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors