cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper III
Helper III

Today's Date, Split by Year, Month and Date

Hi all,

 

I have an API endpoint where I want to dynamically update the date to yesterday's date. However, the date needs to be in the format YYYY-MM-DD. This is my current attempt at doing this is by using this code:

 

Date.Year(DateTime.LocalNow()) & "-" & Date.Month(DateTime.LocalNow()) & "-" & Date.Day(DateTime.LocalNow()-1)

 

...in the context of the query it appears like this:

 

let
Source = Xml.Tables(Web.Contents("https://dataapi.xxxxxx.com/74daa799/v1/enterprise/73/events/xxxxxx/pages/created/2020-09-01;" & Date.Year(DateTime.LocalNow()) & "-" & Date.Month(DateTime.LocalNow()) & "-" & Date.Day(DateTime.LocalNow()-1) ))
in
Source

 

...when I run this I get the following error

 

Expression.Error: We cannot apply operator & to types Text and Number.
Details:
Operator=&
Left=https://dataapi.xxxxxx.com/74daa799/v1/enterprise/73/events/xxxxxx/pages/created/2020-09-01;
Right=2020

 

Can anyone suggest where I'm going wrong?

 

Thanks in advance,

 

Sam

1 ACCEPTED SOLUTION
Super User III
Super User III

Hi @SamBerger 

The error message says you are trying to concatenate text and numbers. Convert the numbers to text with Text.From( ) or similar

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

View solution in original post

2 REPLIES 2
Super User III
Super User III

Hi @SamBerger 

The error message says you are trying to concatenate text and numbers. Convert the numbers to text with Text.From( ) or similar

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

View solution in original post

Perfect! You're a superstar, many thanks @AlB 

 

Sam

Helpful resources

Announcements
secondImage

Congratulations!

We are excited to announce the Power BI Super Users!

Wave Release 2

Check out the updates in Power BI.

Overview of Power BI 2020 release wave 2!

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors