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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
royalswe
Helper I
Helper I

Dynamic date in Odata query

I am fetching data from Dynamics 365 with OData and I only want to fetch data that is 3 days old or newer.

 

I have this query and it works but the date is hardcoded as you can see.

 

royalswe_0-1603897851652.png

 

= OData.Feed("https://sandbox.operations.dynamics.com/Data/SupplyForecastEntries?"
&"$select=LastDate, DeliveryDate, field3"
&"&$top=500"
&"&$filter=LastDate ge 2010-10-01" // Hard coded date
, null, [Implementation="2.0"])

 

Can I change the date part to be dynamic?

1 ACCEPTED SOLUTION
camargos88
Community Champion
Community Champion

@royalswe ,

 

Something like:

 

Date.ToText(Date.AddDays(Date.From(DateTime.FixedLocalNow()), -3), "yyyy-MM-dd")

 

Check if this functions helps:

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



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



View solution in original post

5 REPLIES 5
Syndicate_Admin
Administrator
Administrator

Hi,

I want to change date format in Odata query. It is taking value in format YYYY-MM-DD. 

example of Odata query from Microsoft: 

let
Source = OData.Feed ("https://analytics.dev.azure.com/{organization}/{project}/_odata/V3.0-preview/WorkItemBoardSnapshot?"
&"$apply=filter( "
&"Team/TeamName eq '{teamname}' "
&"and BoardName eq 'Stories' "
&"and DateValue ge 2023-10-18 "
&") "
&"/groupby( "
&"(DateValue,ColumnName,LaneName,State,WorkItemType,AssignedTo/UserName,Area/AreaPath), "
&"aggregate($count as Count) "
&") "
,null, [Implementation="2.0",OmitValues = ODataOmitValues.Nulls,ODataVersion = 4])
in
Source

Now I want to change it to MM-DD-YYYY, can you please provide your input on this how we can convert this?

camargos88
Community Champion
Community Champion

@royalswe ,

 

Something like:

 

Date.ToText(Date.AddDays(Date.From(DateTime.FixedLocalNow()), -3), "yyyy-MM-dd")

 

Check if this functions helps:

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



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Thanks! Worked like a charm 🙂

Anonymous
Not applicable

@royalswe did this work for you in the service as well? I keep getting the error saying dynamic content can't be scheduled?

 

Thanks,

No It didn´t work when scheduled in services.

I had to make the date filter in another row in the M query.

Like this

 

royalswe_0-1606806194379.png

 

let
    Source = OData.Feed("https://sandbox.operations.dynamics.com/Data/SupplyForecastEntries?"
    &"$select=StartDate, SupplyTypeId, LastDate"
    // &"&$filter=ForecastStartDate ge " & Date.ToText(Date.AddDays(Date.From(DateTime.FixedLocalNow()), -3), "yyyy-MM-dd")
    , null, [Implementation="2.0"])
   , #"Filtered Rows" = Table.SelectRows(Source, each [StartDate] >= [LastDate])
in
    #"Filtered Rows"

 

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.

Top Solution Authors