Forum Discussion

mike_asplin's avatar
mike_asplin
Helper V
1 year ago

Help using SQl to limit the data being pulled form Microsoft Dynamics by Odata

I current have a model that is pulling whole tables of data form Microsoft Dynamics anbd then doing al lthe filtering in Power query.  Is therer a way to do the filtering at source like you woudl with an SQL DB? does it speed things up?

 

My current query is

 

Source = OData.Feed("https://chaxxxxx.api.crm11.dynamics.com/api/data/v9.1/", null, [Implementation="2.0"]),
    bookableresourcebookings_table = Source{[Name="bookableresourcebookings",Signature="table"]}[Data],

 

but from this massive table i only want these columns

 

"name", "_cha_clientid_value", "_owningteam_value", "duration", "starttime", "_cha_carercontactid_value", "_msdyn_workorder_value", "msdyn_totalcost", "endtime", "statuscode", "msdyn_milestraveled", "msdyn_actualarrivaltime"

 

Ideally I would have a load parameter of 01/08/2025 00:00:00 and filter startime by this

 

If anyone can help be much appreciated as no idea where to start on the syntax.

 

Thanks 

 

19 Replies

  • Hi mike_asplin 

     

    As you are using odata, it is possible to acheive that

    You can find more information under the following link:
    https://www.odata.org/getting-started/basic-tutorial/


    But to achieve that, you can edit your power query with the following approach:

    let
    
        Url = "https://chaxxxxx.api.crm11.dynamics.com/api/data/v9.1/",
    
        SelectColumns = "name,_cha_clientid_value,_owningteam_value,duration,starttime,_cha_carercontactid_value,_msdyn_workorder_value,msdyn_totalcost,endtime,statuscode,msdyn_milestraveled,msdyn_actualarrivaltime",
    
        FilterDateText = DateTime.ToText(Dateparameter, "yyyy-MM-ddTTHH:mm:ssZ"),
        FilterQuery = "$filter=starttime ge " & FilterDateText,
    
    
        ODataQueryOptions = [
            Query = "$select=" & SelectColumns & "&$" & FilterQuery
        ],
    
           Source = OData.Feed(Url, null, [Implementation="2.0"]),
        bookableresourcebookings_table = Source{[Name="bookableresourcebookings", Signature="table"]}[Data],
        Data = OData.Feed(bookableresourcebookings_table, null, ODataQueryOptions)
    
    in
        Data

     

    Just to be sure to call the date Parameter to Dateparameter and replace the url by the right url and it should work

     

    • mike_asplin's avatar
      mike_asplin
      Helper V

      Thats great and should I expect a big increase in speed?

      • Cookistador's avatar
        Cookistador
        Super User

        Yes, I encountered a similar issue with a customer. It used to take a few minutes for the change to take effect, but now it only takes a few seconds.

        The idea is to filter your data before importing it.

         

        If you do not see an improvement, please post again and we will see how we can improve it.

    • mike_asplin's avatar
      mike_asplin
      Helper V

      Seems ot be taking for ever. Can I check there arent any typoes

       

      Whats the ge for?

      FilterQuery = "$filter=starttime ge " & FilterDateText,

       

      Why is time surrounded by TT and Z?

          FilterDateText = DateTime.ToText(Dateparameter, "yyyy-MM-ddTTHH:mm:ssZ"),

       

      Thanks

      • v-lgarikapat's avatar
        v-lgarikapat
        Community Support

        Hi mike_asplin , 

         

        Thanks for reaching out to the Microsoft fabric community forum

        Cookistador , FBergamaschi 

        Thanks for your prompt response,

        1.

        FilterQuery = "$filter=starttime ge " & FilterDateText,

        ge is one of the OData comparison operators, and it stands for:

        ge = Greater than or Equal to

        It’s the OData equivalent of SQL’s >=. So when you write:

        text

        $filter=starttime ge 2025-08-01T00:00:00Z

        2. 

         FilterDateText = DateTime.ToText(Dateparameter, "yyyy-MM-ddTTHH:mm:ssZ"),

        T

        Time separator between date and time

        2025-08-01T00:00:00

         

        Z

        Zulu time (UTC) indicator

        2025-08-01T00:00:00Z

         

        Open Data Protocol (OData) - Finance & Operations | Dynamics 365 | Microsoft Learn

         

        We truly appreciate your continued engagement and thank you for being an active and valued member of the community.

        If you're still experiencing any challenges, please don’t hesitate to reach out   we’d be more than happy to assist you further.

         

        We look forward to hearing from you.

        Best regards,
        Lakshmi

         

  • Here is where you can input your SQL statement

     

     

    The statement will be something like

     

    SELECT
                  name, _cha_clientid_value, _owningteam_value, duration, starttime, _cha_carercontactid_value, _msdyn_workorder_value, msdyn_totalcost, endtime, statuscode, msdyn_milestraveled, msdyn_actualarrivaltime

    FROM

    bookableresourcebookings

    WHERE

                  the condition on the start time and a final ;

     

    here you find examples to build your syntax

     

    https://www.w3schools.com/sql/sql_examples.asp

     

    If this helped, please consider giving kudos and mark as a solution

    me in replies or I'll lose your thread

    Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page

    Consider voting this Power BI idea

    Francesco Bergamaschi

    MBA, M.Eng, M.Econ, Professor of BI

    • mike_asplin's avatar
      mike_asplin
      Helper V

      The data is not on a SQL server it sin Microsoft dynamics so i'm accessing via OData?