cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
yohanhwang
Regular Visitor

datetime not converting correctly when running python script

Hi.

 

So I get an error that says:

 

DataSource.Error: ADO.NET: Python script error.
<pi>ValueError: time data 'Microsoft.OleDb.Date' does not match format '%m/%d/%Y'
</pi>

 

when running the following portion of my python script in power query editor:

 

result = []
for value in dataset["elcn_contributiondate"]:
    if (datetime.strptime(value, '%m/%d/%Y') >= pd.Timestamp(2018,7,1,12)) & (datetime.strptime(value, '%m/%d/%Y')<= datetime.datetime.now() - relativedelta(years=4)):
        result.append('FY2018')
    elif (datetime.strptime(value, '%m/%d/%Y') >= pd.Timestamp(2019,7,1,12)) & (datetime.strptime(value, '%m/%d/%Y')<= datetime.datetime.now() - relativedelta(years=3)):
        result.append('FY2019')
    elif (datetime.strptime(value, '%m/%d/%Y')>= pd.Timestamp(2020,7,1,12)) & (datetime.strptime(value, '%m/%d/%Y') <= datetime.datetime.now() - relativedelta(years=2)):
        result.append('FY2020')
    elif (datetime.strptime(value, '%m/%d/%Y') >= pd.Timestamp(2021,7,1,12)) & (datetime.strptime(value, '%m/%d/%Y') <= datetime.datetime.now() - relativedelta(years=1)):
        result.append('FY2021')
    elif (datetime.strptime(value, '%m/%d/%Y') >= pd.Timestamp(2022,7,1,12)) & (datetime.strptime(value, '%m/%d/%Y') <= datetime.datetime.now()):
        result.append('FY2022')
    else:
        result.append('no year')
dataset['FY'] = result

 No matter what other version of datetime I try it still errors out. Any help would be greatly appreciated.

0 REPLIES 0

Helpful resources

Announcements
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

BizApps LATAM 2023

Business Application LATAM Summit 2023

Join the biggest FREE Business Applications Event in LATAM this February.

Power Platform Bootcamp

Global Power Platform Bootcamp

In this bootcamp we will deep-dive into Microsoft’s Power Platform stack with hands-on sessions and labs, delivered to you by experts and community leaders.