Forum Discussion

TimHoare's avatar
TimHoare
Frequent Visitor
2 years ago

Direct query limitations with the Snowflake connector

I have a report that connects to a Snowflake database via direct query, and a measure that calculates the median of a column. Because MEDIAN is a function that is supported in Snowflake, ideally the query would be folded back to the database, but I can see that Power BI is instead reading all the data back, then calculating the median locally. Because of this, it is a lot slower than it otherwise would be if it folded the query, and if there are more than one million rows to calculate the median from, it doesn't work at all. The documentation here mentions that "usually the median aggregate isn't supported by the underlying source", but does this mean it will not fold the query for any direct query sources, even though it supported by Snowflake in this case?

2 Replies

  • Update the Snowflake query to use native SQL, something like:

    let
        Source = Value.NativeQuery(
            Snowflake.Databases("server", "warehouse", [Role="role"]){[Name="database"]}[Data],
            "
    sql
            ",
            null,
            [EnableFolding=true]
        )
    in
        Source

    and use MEDIAN() function that way.