参数值的PowerQuery过滤器

时间:2017-08-15 22:16:55

标签: excel powerbi powerquery m

我有一个名为FinancialQuery的Excel PowerQuery FinancialQuery依赖于名为Parameters的表中的值 每次用户更改参数值并单击“刷新”时,查询将根据用户输入

引入数据

但是,财务查询的最后一步是根据相同的参数值过滤行 而不是" 17213"

#"Filtered Rows On OU" = Table.SelectRows(#"Renamed Columns", each [OperatingUnit] = "17213")

我想将过滤器基于相同的函数值fullfilepath

#"Filtered Rows On OU" = Table.SelectRows(#"Renamed Columns", each [OperatingUnit] = fullfilepath)

当我提出语法时,powerquery认为我对单词fullfilepath进行了过滤

有人可以帮我解释语法吗?

这是我的完整代码

'Parameters Table
Parameter   Value
File Path   17213.csv



' fnGetParameter
(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


'Financial Query
let
    fullfilepath = fnGetParameter("File Path"),
    Source = SharePoint.Files("https://Personal.sharepoint.com/FOA/BD", [ApiVersion = 15]),
    #"Filtered Rows" = Table.SelectRows(Source, each ([Folder Path] = "https://Personal.sharepoint.com/FOA/BD/Budget/DataSources/Financials/") and ([Extension] = ".csv") and ([Name] = fullfilepath)),
    #"ActiveFile" = #"Filtered Rows"{[Name=fullfilepath,#"Folder Path"="https://Personal.sharepoint.com/FOA/BD/Budget/DataSources/Financials/"]}[Content],
    #"Imported CSV" = Csv.Document(#"ActiveFile",[Delimiter=",", Columns=23, Encoding=1252, QuoteStyle=QuoteStyle.None]),
    #"Promoted Headers" = Table.PromoteHeaders(#"Imported CSV", [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"P01", Currency.Type}, {"P02", Currency.Type}, {"P03", Currency.Type}, {"P04", Currency.Type}, {"P05", Currency.Type}, {"P06", Currency.Type}, {"P07", Currency.Type}, {"P08", Currency.Type}, {"P09", Currency.Type}, {"P10", Currency.Type},{"P11", Currency.Type},{"P12", Currency.Type}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"P01", "01"}, {"P02", "02"}, {"P03", "03"}, {"P04", "04"}, {"P05", "05"}, {"P06", "06"}, {"P07", "07"}, {"P08", "08"}, {"P09", "09"}, {"P10", "10"}, {"P11", "11"}, {"P12", "12"}}),
    #"Filtered Rows On OU" = Table.SelectRows(#"Renamed Columns", each [OperatingUnit] = "17213")    
in
    #"Filtered Rows On OU"

我还附上了一张powerquery语法的图片。

PowerQuery Syntax

1 个答案:

答案 0 :(得分:0)

我添加了Text.Replace(fullfilepath," .csv","") 最终语法

let
    fullfilepath = fnGetParameter("File Path"),
    Source = SharePoint.Files("https://ihcorp.sharepoint.com/FOA/BD", [ApiVersion = 15]),
    #"Filtered Rows" = Table.SelectRows(Source, each ([Folder Path] = "https://ihcorp.sharepoint.com/FOA/BD/Budget/DataSources/Financials/") and ([Extension] = ".csv") and ([Name] = fullfilepath)),
    #"ActiveFile" = #"Filtered Rows"{[Name=fullfilepath,#"Folder Path"="https://ihcorp.sharepoint.com/FOA/BD/Budget/DataSources/Financials/"]}[Content],
    #"Imported CSV" = Csv.Document(#"ActiveFile",[Delimiter=",", Columns=23, Encoding=1252, QuoteStyle=QuoteStyle.None]),
    #"Promoted Headers" = Table.PromoteHeaders(#"Imported CSV", [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"P01", Currency.Type}, {"P02", Currency.Type}, {"P03", Currency.Type}, {"P04", Currency.Type}, {"P05", Currency.Type}, {"P06", Currency.Type}, {"P07", Currency.Type}, {"P08", Currency.Type}, {"P09", Currency.Type}, {"P10", Currency.Type},{"P11", Currency.Type},{"P12", Currency.Type}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"P01", "01"}, {"P02", "02"}, {"P03", "03"}, {"P04", "04"}, {"P05", "05"}, {"P06", "06"}, {"P07", "07"}, {"P08", "08"}, {"P09", "09"}, {"P10", "10"}, {"P11", "11"}, {"P12", "12"}}),
    #"Filtered Rows1" = Table.SelectRows(#"Renamed Columns", each [OperatingUnit] = Text.Replace(fullfilepath,".csv",""))
in
    #"Filtered Rows1"