我最初用静态StartDate和EndDate在PowerQuery中创建了一个SQL代码(参见下面的代码)。
带有静态值的SQL脚本:
Select extract(month from STAGE_DATE) as Calendar_Month, count(id) as
number_of_int
from stage_table
where type_code LIKE 'X%'
and stage_date >= to_date('01022021','ddmmyyyy') ---StartDate
and stage_date <= to_date('30042021','ddmmyyyy') ---EndDate
group by extract(month from STAGE_DATE)但是,我希望用户能够更改StartDate和EndDate。经过一些研究,有一个叫做高级编辑器的函数可以使用。我创建了一个名为参数的表(Insert-> Table):
Column 1: Parameter Column 2: Value
StartDate 01022021
EndDate 30042021然后,我使用“高级编辑器”来定义参数表。首先,我将StartDate命名为:
(ParameterName as text) =>
let
ParamSource = Excel.CurrentWorkbook(){[Name="Parameters"]}[Content],
ParamRow = Table.SelectRows(ParamSource, each ([Parameter] = ParameterName)),
Value=
if Table.IsEmpty(ParamRow)=true
then null
else Record.Field(ParamRow{0},"Value")
in
Value然后我在初始的SQL中输入了fnGetParameter('StartDate'),但是我一直收到一条错误消息,上面写着:"DataSource.Error: DataSource.Error: ORA-00904:“FNGETPARAMETER:无效标识符”
Select extract(month from STAGE_DATE) as Calendar_Month, count(id) as
number_of_int
from stage_table
where type_code LIKE 'X%'
and stage_date >= to_date(fnGetParameter('StartDate'),'ddmmyyyy')
and stage_date <= to_date(fnGetParameter('EndDate'),'ddmmyyyy')
group by extract(month from STAGE_DATE)谢谢你提前调查这件事!
发布于 2021-12-09 15:21:17
我建议您使用Ken的fnGetParameter()函数
您还可以看到excel-power-query-using-sql-to-pass-row-value-as-parameter
//Written by Ken Puls, FCPA, FCMA, MS MVP (Excel)
//Original Source: http://www.excelguru.ca/blog/2014/11/26/building-a-parameter-table-for-power-query/
(ParameterName as text) =>
let ParamSource = Excel.CurrentWorkbook(){[Name="Parameters"]}[Content],
ParamRow = Table.SelectRows(ParamSource, each ([Parameter] = ParameterName)),
Value=if Table.IsEmpty(ParamRow)=true
then null
else Record.Field(ParamRow{0},"Value")
in Value然后将StartDate替换为fnGetParameter("StartDate")
https://stackoverflow.com/questions/70284860
复制相似问题