Forum Discussion

shamilka's avatar
shamilka
Frequent Visitor
2 years ago
Solved

Getting only the latest database data instead of downloading the whole table in the beggining

Hi All,    I'm using the following code to load the data to Power BI. Since my filteration at the the next step of the code, it will download the whole table. I want to download only the latest dat...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi shamilka ,

    I will use SQL Server as datasource for an example:
    Sample data (Today is 2024.8.20):

    When connecting to SQL Server:

    Here is the SQL Code in the SQL statement:

    select * from Table_4 where date <= CAST(GETDATE() as date) AND date >= DATEADD(DAY, -15, CAST(GETDATE() as date));

    And the final output is as below:


    Here is the M code in Advanced Editor:

    let
        Source = Sql.Database("DM1", "Import", [Query="select * from Table_4 where date <= CAST(GETDATE() as date) AND date >= DATEADD(DAY, -15, CAST(GETDATE() as date));"])
    in
        Source

     

    Best Regards,
    Dino Tao
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.