在同一工作簿中引用命名范围单元格(验证列表)以更改 Excel Sage Sequel 数据库 Power Query 中的帐号筛选器

问题描述 投票:0回答:1

我正在尝试从下图中的命名范围单个单元格 D3 动态更改 Excel Sage Power Query 中的筛选器。 D3 是同一工作簿中会计科目表的选择列表。 Stackoverflow query 根据图像,动态 MonthNo 对于选择周期很有用,并且我对动态帐号使用了相同/类似的代码,但是当它读取 AccountNo (命名范围)时,它会给出正确的结果,但是表格显示为空,如下图所示。 Table Empty 我的代码如下:-

let
MonthNo= Text.From(Excel.CurrentWorkbook(){[Name="MonthNo"]}[Content]{0}[Column1]),
**AccountNo= Text.From(Excel.CurrentWorkbook(){[Name="AccountNo"]}[Content]{0}[Column1]), **
Source = Sql.Database("XXXX\SAGEXXX", "UKXXXXXXLtd", [Query="SELECT #(lf)NLNominalAccount.AccountNumber, NLNominalAccount.AccountCostCentre, NLNominalAccount.AccountDepartment, NLNominalAccount.AccountName,#(lf)NLPostedNominalTran.TransactionDate, NLPostedNominalTran.PostedDate, NLPostedNominalTran.GoodsValueInBaseCurrency, NLPostedNominalTran.Reference,#(lf)NLPostedNominalTran.Narrative, NLPostedNominalTran.UniqueReferenceNumber, NLPostedNominalTran.UserName, NLPostedNominalTran.UserNumber,#(lf)SYSAccountingPeriod.PeriodNumber#(lf)FROM NLPostedNominalTran, NLNominalAccount, SYSAccountingPeriod, SYSFinancialYear#(lf)WHERE NLPostedNominalTran.NLNominalAccountID = NLNominalAccount.NLNominalAccountID#(lf)AND NLPostedNominalTran.SYSAccountingPeriodID = SYSAccountingPeriod.SYSAccountingPeriodID#(lf)AND SYSAccountingPeriod.SYSFinancialYearID = SYSFinancialYear.SYSFinancialYearID#(lf)AND SYSAccountingPeriod.PeriodNumber <="&MonthNo&"#(lf)ORDER BY NLPostedNominalTran.UniqueReferenceNumber DESC"]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"TransactionDate", type date}, {"GoodsValueInBaseCurrency", Currency.Type}, {"PostedDate", type date}}),
    Custom1 = Table.AddColumn(#"Changed Type", "Date Time Refresh", each DateTime.LocalNow() as datetime),
    #"Changed Type1" = Table.TransformColumnTypes(Custom1,{{"Date Time Refresh", type datetime}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type1",{{"AccountNumber", "Account Number"}, {"AccountCostCentre", "Cost Centre"}, {"AccountDepartment", "Department"}, {"AccountName", "Account Name"}, {"TransactionDate", "Trans Date"}, {"PostedDate", "Posted Date"}, {"GoodsValueInBaseCurrency", "Posted Value"}, {"Reference", "Journal Ref"}, {"Narrative", "Journal Narrative"}, {"UniqueReferenceNumber", "URN"}, {"UserName", "User Name"}, {"UserNumber", "User Number"}, {"PeriodNumber", "Posted Period"}}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Renamed Columns",{{"Posted Value", Currency.Type}}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Filtered Rows", "Trans Date", "Trans Date - Copy"),
    #"Reordered Columns" = Table.ReorderColumns(#"Duplicated Column",{"Account Number", "Cost Centre", "Department", "Account Name", "Trans Date", "Posted Date", "Posted Value", "Journal Ref", "Journal Narrative", "URN", "User Name", "User Number", "Trans Date - Copy", "Posted Period", "Date Time Refresh"}),
    #"Extracted Year" = Table.TransformColumns(#"Reordered Columns",{{"Trans Date - Copy", Date.Year, Int64.Type}}),
    #"Renamed Columns1" = Table.RenameColumns(#"Extracted Year",{{"Trans Date - Copy", "Year"}}),
    #"Filtered Rows" = Table.SelectRows(#"Reordered Columns1", each ([Full Account No] = **"&AccountNo&"**)),
    #"Sorted Rows" = Table.Sort(#"Renamed Columns1",{{"Year", Order.Ascending}, {"Posted Period", Order.Ascending}, {"Trans Date", Order.Ascending}})
    in
    #"Sorted Rows"

我已经尝试了基于动态月份编码的上述代码,结果为空表,因此不是动态过滤。我尝试了各种替代迭代但没有成功。我还尝试将

AccountNo= Text.From
更改为
AccountNo= Number.From
,这会出现错误,而在查看 AccountNo 步骤时使用文本,我可以看到帐号的结果。

我还希望增加复杂性,如果在 D3(空白)中选择“无帐号”,则尽可能应用“无过滤器”。

非常感谢您的麻烦。

加里

excel powerquery sage
1个回答
0
投票

您的代码中没有名为 #"Reordered Columns1" 的步骤,但您正在尝试过滤该步骤。这可能就是问题所在。也许您想使用之前的步骤名称来过滤 #"Renamed Columns1"?

我假设您从不在您共享的代码中的某个地方获得AccountNo,因为它也不在那里

© www.soinside.com 2019 - 2024. All rights reserved.