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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
Anonymous
Not applicable

Power Query - Formula Error (Custom Column)

Hi Experts...

 

I cannot work out how to reslove the following error message. 
My capture_day_id is in the format 2020101 and not 01/01/20

My expiration_day_id is in the format 2020101 and not 01/01/20

 

I am trying to work out the duration in days between the two dates.

 

 

Invesco_0-1660815274175.png

 

 

List.Dates(
Date.FromText([capture_day_id]),

Duration.Days(
#date(Number.FromText(Text.Start([capture_day_id],4)), Number.FromText(Text.Middle([capture_day_id],4,2)),Number.FromText(Text.End([capture_day_id],2)))
,
#date(Number.FromText(Text.Start([expiration_day_id],4)), Number.FromText(Text.Middle([expiration_day_id],4,2)),Number.FromText(Text.End([expiration_day_id],2)))
),

#duration(1, 0, 0, 0))

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , try Date.FromText([capture_day_id])

 

refer https://docs.microsoft.com/en-us/powerquery-m/date-fromtext

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@Anonymous , try Date.FromText([capture_day_id])

 

refer https://docs.microsoft.com/en-us/powerquery-m/date-fromtext

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Same error message

@Anonymous , Yes, I also checked out. if only MM can be 1,2, 3 etc then we can do like

 

if then Text.Length(Text.Length) = 7 then #date(Number.FromText(Text.Start([capture_day_id],4)), Number.FromText(Text.Middle([capture_day_id],4,1)),Number.FromText(Text.End([capture_day_id],2)))
else #date(Number.FromText(Text.Start([capture_day_id],4)), Number.FromText(Text.Middle([capture_day_id],4,2)),Number.FromText(Text.End([capture_day_id],2)))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Slightly confused - can you add the full formula PLEASE. Thanks

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.