Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Is a Custom SQL Query considered as non-folded?

Hi, I am playing with Incremental refreshes on a "Ticket Table",  Unfortunately, the field that I am using to flag new/changed data is a "date closed" field, which is nullable. What I have done in ...
  • AntrikshSharma's avatar
    3 years ago

    Anonymous If you use SQL code for importing data then Query Folding breaks, however what you can do is first create a connection to the database in PQ and then add a new step that will use the function Value.NativeQuery

    let
        Source = Sql.Databases ( "autumn\sql2019" ),
        ContosoRetailDW = Source{[ Name = "ContosoRetailDW" ]}[Data],
        //Query is now folded                     
        EnableFolding = 
            Value.NativeQuery (
                ContosoRetailDW,
                "SELECT * FROM DimProduct",
                null,
                [ EnableFolding = true ]
            ),
        FilterRows = 
            Table.SelectRows ( 
                EnableFolding, 
                each [ProductKey] <> 3
            )
    in
        FilterRows

    But I would suggest you create a View so that you can add an additional layer between tables and PQ, makes it easy to govern and DBA would know if a View depends on a table and will modify accordingly.