For our business we use PowerQuery/PowerBI to analyse data from databases in Postgres. Overall this is in general a very nice way to link databases with Excel.
Unfortunately the language for the formulas is a bit clumsy. The documentation can be found here. It is also annoying that the query source gets changed after compilation in Excel.
This post is mainly intented to keep track of how to add a parameter to a power query.
My personal raw version looks like this:
let
Source = (daysBack)=>PostgreSQL.Database(„host“, „user“, [Query=“select * from analysis where as_of_date > CURRENT_DATE – INTERVAL ‚ “ & Text.From(daysBack)& “ day'“])
in
Source
Excel translates this then into
let
Source = (daysBack)=>PostgreSQL.Database(„host“, „user“, [Query=“select * from analysis where as_of_date > CURRENT_DATE – INTERVAL ‚ “ & Text.From(daysBack)& “ day'“]),
#“Invoked FunctionSource“ = Source(3)
in
#“Invoked FunctionSource“