<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Dynamic Date function as parameter in JSON data source not working in Power Query</title>
    <link>https://community.fabric.microsoft.com/t5/Power-Query/Dynamic-Date-function-as-parameter-in-JSON-data-source-not/m-p/1096848#M36498</link>
    <description>&lt;P&gt;Thanks we are 1/2 way there now!&lt;/P&gt;&lt;P&gt;I changed yours to add the Zone, since it requires a DateTimeZone format but it is different zone format&lt;BR /&gt;AND no .format is available.&lt;BR /&gt;so i need a way now to format the zone string in this format.&lt;BR /&gt;{date.format("yyyy-MM-dd'T'HH:mm:ssZ").tostring()}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;GetTodayDate = Text.From(DateTimeZone.LocalNow()),&lt;BR /&gt;SevenDaysAgo = Text.From(Date.AddDays(DateTimeZone.LocalNow(),-7)),&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;DataSource.Error: Web.Contents failed to get contents from 'http://secret URL/select?defType=lucene&amp;amp;facet=false&amp;amp;q=orderDate:%5B5/12/2020%202:25:36%20PM%20-05:00+TO+5/19/2020%202:25:36%20PM%20-05:00%5D&amp;amp;rows=50000&amp;amp;sort=orderDate+desc&amp;amp;start=0&amp;amp;wt=json' (400): Bad Request&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;that seems to work for the first part because it does put a date in, however the format is wrong.&lt;BR /&gt;5/12/2020%202:25:36%20PM%20-05:00&lt;/P&gt;&lt;P&gt;2020-05-07T00:00:00.000Z&lt;BR /&gt;It has to use dashes and THIS DateTimeZone format.&amp;nbsp; do you know of a .format command that works with DateTimeZone?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 19 May 2020 19:29:38 GMT</pubDate>
    <dc:creator>landcruiser64</dc:creator>
    <dc:date>2020-05-19T19:29:38Z</dc:date>
    <item>
      <title>Dynamic Date function as parameter in JSON data source not working</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Dynamic-Date-function-as-parameter-in-JSON-data-source-not/m-p/1096694#M36496</link>
      <description>&lt;P&gt;--------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;Goal: Pass Date Parameters to the Data Source pointing to JSON to get data from 7 days ago until today&lt;/P&gt;&lt;P&gt;-------------------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;JSON Data Source Connection String&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://our" target="_blank" rel="noopener"&gt;http://our&lt;/A&gt; secret URL/select?defType=lucene&amp;amp;facet=false&amp;amp;q=orderDate:%5B2020-05-07T00:00:00.000Z+TO+2020-05-14T23:59:59.999Z%5D&amp;amp;rows=5000000&amp;amp;sort=orderDate+desc&amp;amp;start=0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%5B&lt;/P&gt;&lt;P&gt;2020-05-07T00:00:00.000Z&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - needs to be replaced with a dynamic date of 7 days ago&lt;/P&gt;&lt;P&gt;+TO+&lt;/P&gt;&lt;P&gt;2020-05-14T23:59:59.999Z&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - needs to be replaced with a dynamic date of Today&lt;/P&gt;&lt;P&gt;%5D&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We also tried lots of different formatting things and syntax like:&lt;/P&gt;&lt;P&gt;{date.addHours(-15).format("yyyy-MM-dd'T'HH:mm:ssZ").tostring()}&lt;/P&gt;&lt;P&gt;{date.today.format().tostring()}&lt;/P&gt;&lt;P&gt;But nothing seems to work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-------------------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;4 solutions&lt;/P&gt;&lt;P&gt;----------------------------------------------------&lt;/P&gt;&lt;P&gt;1 Date Functions in the Data Source Direct&lt;/P&gt;&lt;P&gt;2 Parameter&lt;/P&gt;&lt;P&gt;3 Function&lt;/P&gt;&lt;P&gt;4 Query&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;----------------------------------------------------&lt;/P&gt;&lt;P&gt;1 Date Functions in the Data Source Direct&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;= Json.Document(Web.Contents("&lt;A href="http://our%20secret%20URL/select?defType=lucene&amp;amp;facet=false&amp;amp;q=orderDate:%5B" target="_blank" rel="noopener"&gt;http://our secret URL/select?defType=lucene&amp;amp;facet=false&amp;amp;q=orderDate:%5B&lt;/A&gt;"&amp;amp;SevenDaysAgo&amp;amp;"+TO+"&amp;amp;GetTodayDate&amp;amp;"%5D&amp;amp;rows=5000000&amp;amp;sort=orderDate+desc&amp;amp;start=0" &amp;amp; "&amp;amp;wt=json"))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Expression.Error: We cannot apply operator &amp;amp; to types Text and Function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;----------------------------------------------------&lt;/P&gt;&lt;P&gt;2 Parameter&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Parameters setup: SevenDaysAgo and GetTodayDate&lt;/P&gt;&lt;P&gt;-- WORKS when I hard code these to datetimezone values if works fine but NOT dynamic&lt;/P&gt;&lt;P&gt;SevenDaysAgo = 2020-05-07T00:00:00.000Z&lt;/P&gt;&lt;P&gt;GetTodayDate = 2020-05-14T23:59:59.999Z&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SevenDaysAgo = 2020-05-07&lt;/P&gt;&lt;P&gt;GetTodayDate = 2020-05-14&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - which makes it a TimeZONE issue, what TimeZONE does Dax Return for DateTimeZone?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#datetimezone(2011, 8, 16, 23, 34, 37.745, 0, 0)&lt;/P&gt;&lt;P&gt;"12/31/2010 11:56:02 AM +08:00"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DataSource.Error: Web.Contents failed to get contents from&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ZonedDateTime zdt = ZonedDateTime.parse("2017-01-11T09:38:41+0100", dtf);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-- if I add a DateTImeZone.UtcNow or LocalNow as the parameter value&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Expression.Error: We cannot apply operator &amp;amp; to types Text and Function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;----------------------------------------------------&lt;/P&gt;&lt;P&gt;3 Function&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;GetNow = () =&amp;gt; "DateTimeZone.UtcNow"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Expression.Error: We cannot apply operator &amp;amp; to types Text and Function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;----------------------------------------------------&lt;/P&gt;&lt;P&gt;4 Query&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;GetToday = DateTimeZone.UtcNow&lt;/P&gt;&lt;P&gt;DataSource.Error: Web.Contents failed to get contents from&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;----------------------------------------------------&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 16:55:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Dynamic-Date-function-as-parameter-in-JSON-data-source-not/m-p/1096694#M36496</guid>
      <dc:creator>landcruiser64</dc:creator>
      <dc:date>2020-05-19T16:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Date function as parameter in JSON data source not working</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Dynamic-Date-function-as-parameter-in-JSON-data-source-not/m-p/1096836#M36497</link>
      <description>&lt;P&gt;Hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="120578" data-lia-user-login="landcruiser64" class="lia-mention lia-mention-user"&gt;landcruiser64&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You sem to be getting two different types of errors, one related to the code but another one realted to the web site not being reachable. Are you sure the URL you put together actually is actually reachable? Try this:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;let
    GetTodayDate = Text.From(DateTime.LocalNow()),
    SevenDaysAgo = Text.From(Date.AddDays(DateTime.LocalNow(),-7)), 
    Source = Web.Contents("http://our secret URL/select?defType=lucene&amp;amp;facet=false&amp;amp;q=orderDate:%5B"&amp;amp; SevenDaysAgo &amp;amp;"+TO+"&amp;amp; GetTodayDate &amp;amp;"%5D&amp;amp;rows=5000000&amp;amp;sort=orderDate+desc&amp;amp;start=0" &amp;amp; "&amp;amp;wt=json")
in
    Source&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;Please mark the question solved when done and consider &lt;FONT color="#FF9900"&gt;giving kudos if posts are helpful.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;Contact me privately for support with any larger-scale BI needs&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Cheers&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 19:10:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Dynamic-Date-function-as-parameter-in-JSON-data-source-not/m-p/1096836#M36497</guid>
      <dc:creator>AlB</dc:creator>
      <dc:date>2020-05-19T19:10:28Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Date function as parameter in JSON data source not working</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Dynamic-Date-function-as-parameter-in-JSON-data-source-not/m-p/1096848#M36498</link>
      <description>&lt;P&gt;Thanks we are 1/2 way there now!&lt;/P&gt;&lt;P&gt;I changed yours to add the Zone, since it requires a DateTimeZone format but it is different zone format&lt;BR /&gt;AND no .format is available.&lt;BR /&gt;so i need a way now to format the zone string in this format.&lt;BR /&gt;{date.format("yyyy-MM-dd'T'HH:mm:ssZ").tostring()}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;GetTodayDate = Text.From(DateTimeZone.LocalNow()),&lt;BR /&gt;SevenDaysAgo = Text.From(Date.AddDays(DateTimeZone.LocalNow(),-7)),&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;DataSource.Error: Web.Contents failed to get contents from 'http://secret URL/select?defType=lucene&amp;amp;facet=false&amp;amp;q=orderDate:%5B5/12/2020%202:25:36%20PM%20-05:00+TO+5/19/2020%202:25:36%20PM%20-05:00%5D&amp;amp;rows=50000&amp;amp;sort=orderDate+desc&amp;amp;start=0&amp;amp;wt=json' (400): Bad Request&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;that seems to work for the first part because it does put a date in, however the format is wrong.&lt;BR /&gt;5/12/2020%202:25:36%20PM%20-05:00&lt;/P&gt;&lt;P&gt;2020-05-07T00:00:00.000Z&lt;BR /&gt;It has to use dashes and THIS DateTimeZone format.&amp;nbsp; do you know of a .format command that works with DateTimeZone?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 19:29:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Dynamic-Date-function-as-parameter-in-JSON-data-source-not/m-p/1096848#M36498</guid>
      <dc:creator>landcruiser64</dc:creator>
      <dc:date>2020-05-19T19:29:38Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Date function as parameter in JSON data source not working</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Dynamic-Date-function-as-parameter-in-JSON-data-source-not/m-p/1096871#M36499</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="120578" data-lia-user-login="landcruiser64" class="lia-mention lia-mention-user"&gt;landcruiser64&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is the time that yopu want always 00:00:00.000? If so, use this:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;GetTodayDate = Text.Replace(Text.Start(Text.From(DateTime.LocalNow()),10),"/","-") &amp;amp; "T00:00:00.000Z",
SevenDaysAgo = Text.Replace(Text.Start(Text.From(Date.AddDays(DateTime.LocalNow(),-7)),10),"/","-") &amp;amp; "T00:00:00.000Z"&lt;/LI-CODE&gt;
&lt;P&gt;&lt;STRONG&gt;Please mark the question solved when done and consider &lt;FONT color="#FF9900"&gt;giving kudos if posts are helpful.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;Contact me privately for support with any larger-scale BI needs&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Cheers&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 20:06:29 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Dynamic-Date-function-as-parameter-in-JSON-data-source-not/m-p/1096871#M36499</guid>
      <dc:creator>AlB</dc:creator>
      <dc:date>2020-05-19T20:06:29Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Date function as parameter in JSON data source not working</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Dynamic-Date-function-as-parameter-in-JSON-data-source-not/m-p/1096897#M36502</link>
      <description>&lt;P&gt;Getting really close.&amp;nbsp; I think it is flipping the format of the date around now.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;5-12-2020 T00:00:00.000Z TO 5-19-2020 T00:00:00.000Z&lt;BR /&gt;needs to be:&lt;BR /&gt;2020-05-12T00:00:00.000Z TO 2020-05-19T00:00:00.000Z&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is there no date format, since you are doing text replaces?&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 20:25:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Dynamic-Date-function-as-parameter-in-JSON-data-source-not/m-p/1096897#M36502</guid>
      <dc:creator>landcruiser64</dc:creator>
      <dc:date>2020-05-19T20:25:10Z</dc:date>
    </item>
  </channel>
</rss>

