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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Syndicate_Admin
Administrator
Administrator

Power BI API with Dynamics 365

Hello all,

 

Dynamics SAAS environments limits data size for API calls.

 

As a business analyst without IT/IS background I got things working to the below degree.

An API call out of Power Query (without variable A and B) on Dynamics365 is active and working:

 

The filter on "generalPostingGroup" is working fine. The desired result is obtained but incomplete due to the limitations of API data volume which the SAAS Dynamics 365 database is supplying.

 

Now I am looking for a way to limit the requested data volume by filtering on a dynamic date range by adding the variables like shown above. Based on M-code DateTime.LocalNow() the variable A and variable B can be set.

Is there a way to make this work?

 

Does anybody know if this is feasible and if so, how to get this working in the PowerBI environment?

Thanks much for the effort of all you great participants in this community!

 

 

 

3 REPLIES 3
Syndicate_Admin
Administrator
Administrator

Uereka, Solved!

 

The magic is in the use of spaces or %20.

The correct syntax turned out to be:

No need to use single and double quotes around the variables. 

 

Text strings must be separated by space which are translated as %20 in the query. Between the ge/lt strings and the quote sign make sure the is a space, also between the closing quote after the first variable (startDate) and the and string leave a space. In this respect the proposed solution by Syndicate Admin was correct

 

A lot of trial and error to find this.

All references I found are not clear in this respect and copying the proposed solution syntax was not successful.

As always: the devil is in the detail!

 

On to the next challenge.

 

Syndicate_Admin
Administrator
Administrator

Thanks so much Jing. This is great and helps a lot.

 

Looks like this puts me on the right track but not yet over the finish line.

When making a call without the variables de filter data element postingDate comes down in Date format like 31-12-2021.  The variables are formatted accordingly as shown below and further conversion in the urlString is not needed.

 

The single and double quotes around the variables have been switched: double quotes inside the single quote otherwise there is an error message " end of line missing comma".

 

With the above syntax I get the error message that the & operator cannot be used on text or date types. 

Is there a solution for this.

 

Once again, help greatly appreciated.

 

Best regards

Paul

v-jingzhang
Community Support
Community Support

Hi 

 

You can try something like this

let
    pStartDate = Date.AddDays(DateTime.LocalNow(),-10), // 10 days prior of today
    pEndDate = DateTime.LocalNow(), // today
    urlString = "https://xxxxxxxxxxxxx and postingDate ge '" & Text.From(pStartDate) & "' and postingDate lt '" & Text.From(pEndDate) & "'",
    Source = Json.Document(Web.Contents(urlString))
in
    Source

 

The pStartDate and pEndDate may not be in the correct format that this API requires, you can use Date.ToText or DateTime.ToText function to change its format. 

 

If you want to set scheduled refresh, above query will give you an dynamic data source cannot be refreshed error. In that case, you need to set RelativePath and Query options with Web.Contents(). Please refer to

Chris Webb's BI Blog: Using The RelativePath And Query Options With Web.Contents() In Power Query An...

Web.Contents with complex Query parameter names - Microsoft Power BI Community

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.