简体   繁体   中英

Use stored procedure with parameters in PowerBI

I use PowerBI (October 2020), and I have one dashboard with a drop down DATE slicer. I have two problems with it:

  1. I need to pass the value of slicer to a stored procedure to use there as a where condition. I mean the query has used in stored procedure, filtered by the date has picked in slicer.

  2. I need keep update the value of slicer too. I means if today is 2021/08/10, this date shows in slicer and tomorrow is become 2020/08/11 automatically.

If somebody can provide some solution that would be great.

Thanks in advance

1). You have to create 2 parameters for selecting data range if you use stored procedure. Similar thing happen to me earlier, so I switched from stored procedure to mysql or sql views. I managed to get data via join queries and optimize it. Because if you use Views you have some limitations. If you have correct requirement hardcode lower bound date, and if you use view it act as mysql table.

2). If you have date slicer in the filters you can change it to relative date to selected time, then your upper bound date will update accordingly.

After hours of testing I have the strong opinion that it is not possible to call SQL stored procedures with parameters and DirectQuery, affected by user controls in a PowerBI dashboard.

  • This is easily done in PowerBI Report Builder.
  • You can create parameters in PowerBI that affect the parameter-values in your SQL-stored procedures but they are not adjustable by the user in your dashboard.

The syntax for the call to SQL SP is:

let
    Source = Sql.Database("[server]", "[database]", [Query="EXEC direct.sp_[stored procedure] '" & DateTime.ToText(prmStartDatum) & "', '" & DateTime.ToText(prmEindDatum) & "'", CommandTimeout=#duration(0, 0, 10, 0), HierarchicalNavigation=true, MultiSubnetFailover=true])
in
    Source

The error you get is:

Microsoft SQL: Incorrect syntax near the keyword 'EXEC'. Incorrect syntax near ')'.

When this is fixed, it would be a great improvement to PowerBI dashboards.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM