电源 BI.使用用户参数执行 SQL Server 存储过程

2022-01-10 00:00:00 powerbi sql-server stored-procedures

我有一个 Power BI 报告和一个带有 @DateFrom 参数的存储过程,该参数返回多行.我想允许用户选择将传递给存储过程的日期.(使用 DirectQuery 模式)

I have a Power BI report and a stored procedure with a @DateFrom parameter which returns a number of rows. I want to allow user to choose the date which will be passed to stored procedure. (Using DirectQuery mode)

对于这个简单的任务,我找到了零解决方案.也许我什么都不懂,但这是一个很常见的问题,Power BI 开发人员似乎忽略了它.

I have fount zero solutions to this simple task. Maybe I don't understand anything, but it's quite a common problem, which seems to be ignored by Power BI developers.

这是我的存储过程:

EXEC [rpt].[sp_rpt_bids_statictics_2] @DateFrom = '20160101'

现在我想让用户选择那个日期,例如20160501",然后查询如下:

Now I want to allow user to choose that very date, fore example '20160501' and then the query will be the following:

EXEC [rpt].[sp_rpt_bids_statictics_2] @DateFrom = '20160501'

在 Microsoft Power BI 中是否可行?

is it possible in Microsoft Power BI?

推荐答案

好的,我找到了解决方案.

Ok, I have found the solution.

  1. 添加一个参数并允许加载它.(例如它的名字是 Query_param_1)
  2. 在导入模式下创建查询(仅此模式允许)
  3. 然后为创建的查询打开扩展集编辑器
  4. 编辑查询部分:
  5. [Query="EXEC [rpt].[sp_rpt_bids_statictics_2] @DateFrom = '"Query_param_1"'"]
  6. 现在它可以与用户选择的参数一起使用.

相关文章