Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Get data from specific date range- ODBC

Hello,

 

I am trying to import the last 5 years worth of data from a database with an ODBC connection. It has over 30 years of data slowing my dashboard down. What code can I use to only pull a certain amount of data and where do I put it? Thanks for your help

  • Hi, Anonymous ;

       In the From ODBC dialog box, expand the Data Source Name (DSN) drop-down list and select the DSN that you’ve configured for your data source. Optionally, you can enter a SQL statement to execute against the ODBC driver in the Advanced options -- for example, if you want to filter or sort the data in the table rather than to load the entire dataset. Click OK.  If your data source is password-protected, Power BI will prompt you for the username and password. Type them into the respective fields and click OK. 

    You could write SQL to filter data.like below:

    SELECT * FROM myODBC WHERE year(Date)>=year(getdate())-5
    SELECT Select DateAdd(yyyy,-3,getdate()) FROM myODBC 

    https://www.w3school.com.cn/sql/func_datediff.asp

    https://community.powerbi.com/t5/Community-Blog/How-to-Connect-to-an-ODBC-Data-Source-From-Power-BI/ba-p/960701

     

    Best Regards,
    Community Support Team_ Yalan Wu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

5 Replies

  • That entirely depends on your ODBC source. Does it support native queries?

  • v-yalanwu-msft's avatar
    v-yalanwu-msft
    Community Support

    Hi, Anonymous ;

       In the From ODBC dialog box, expand the Data Source Name (DSN) drop-down list and select the DSN that you’ve configured for your data source. Optionally, you can enter a SQL statement to execute against the ODBC driver in the Advanced options -- for example, if you want to filter or sort the data in the table rather than to load the entire dataset. Click OK.  If your data source is password-protected, Power BI will prompt you for the username and password. Type them into the respective fields and click OK. 

    You could write SQL to filter data.like below:

    SELECT * FROM myODBC WHERE year(Date)>=year(getdate())-5
    SELECT Select DateAdd(yyyy,-3,getdate()) FROM myODBC 

    https://www.w3school.com.cn/sql/func_datediff.asp

    https://community.powerbi.com/t5/Community-Blog/How-to-Connect-to-an-ODBC-Data-Source-From-Power-BI/ba-p/960701

     

    Best Regards,
    Community Support Team_ Yalan Wu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • v-yalanwu-msft's avatar
    v-yalanwu-msft
    Community Support

    Hi, Anonymous ;

    Is your problem solved?? If so, Would you mind accept the helpful replies as solutions? Then we are able to close the thread. More people who have the same requirement will find the solution quickly and benefit here. Thank you.

    Best Regards,
    Community Support Team_ Yalan Wu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • dhruvip23's avatar
    dhruvip23
    Regular Visitor

    I have same quastion but instead of ODBC, I want to import the last 5 years data from Azure Analytical Service database.

    • lbendlin's avatar
      lbendlin
      Super User

      That is a very different connector with very different capabilities.

       

      Please open a new thread with your question.