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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.