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
MorvenMoeller
New Member

List.Difference between a list of dates and a list of strings

I have a list of all project dates - dates in a list, and a list of out-of-office dates - dates as strings in a list.

 

When I List.Difference([All Project Dates], [OOO Dates]), it obviously doesn't work.

 

How can I transform/convert a list of dates as strings into a list of dates as dates?  Or vice versa?

 

Thanks!

 

MorvenMoeller_0-1715302685547.pngMorvenMoeller_1-1715302705433.png

 

MorvenMoeller_2-1715302794043.png

 

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @MorvenMoeller 

The function to convert text > date is Date.FromText.

You could apply it in this case by changing

 

[OOO Dates]

 

to

 

List.Transform( [OOO Dates], each Date.FromText(_[Format="M/d/yyyy"]) )

 

within your existing code.

 

You could also add a separate step with Table.TransformColumns to transform the [OOO Dates] column from text list to date list, and then apply List.Difference.

 

= Table.TransformColumns(
    PreviousStep,
    { {"OOO Dates", each List.Transform(_, each Date.FromText(_, [Format = "M/d/yyyy"]) ), type {date}} }
  )

 

 Are you able to get this working?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

2 REPLIES 2
MorvenMoeller
New Member

Thank you!  I have been running in circles for almost an hour.  Much appreciated!!

OwenAuger
Super User
Super User

Hi @MorvenMoeller 

The function to convert text > date is Date.FromText.

You could apply it in this case by changing

 

[OOO Dates]

 

to

 

List.Transform( [OOO Dates], each Date.FromText(_[Format="M/d/yyyy"]) )

 

within your existing code.

 

You could also add a separate step with Table.TransformColumns to transform the [OOO Dates] column from text list to date list, and then apply List.Difference.

 

= Table.TransformColumns(
    PreviousStep,
    { {"OOO Dates", each List.Transform(_, each Date.FromText(_, [Format = "M/d/yyyy"]) ), type {date}} }
  )

 

 Are you able to get this working?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

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.

Top Solution Authors
Top Kudoed Authors