[英]Filter one Power BI Query based on an Excel Table
I have a table called "_Vendor_List" in a spreadsheet and I use this to filter a query in that spreadsheet which I use for analytics.我在电子表格中有一个名为“_Vendor_List”的表,我使用它来过滤该电子表格中用于分析的查询。
Similarly, I would like to filter the same query in Power BI based on this same table.同样,我想根据同一个表在 Power BI 中过滤相同的查询。 This works in excel, but I'm not sure if/how the syntax varies in Power BI for the Query.
这在 excel 中有效,但我不确定 Power BI 中查询的语法是否/如何变化。
My Excel Power Query Code is:我的 Excel Power Query 代码是:
let
Source = Sql.Database("MyDatabase", "MY_DATA"),
ExcelTable = Excel.CurrentWorkbook(){[Name="_Vendor_List"]}[Content],
#"PerformanceTable" = Source{[Schema="dbo",Item="PerformanceTable"]}[Data],
Filter = Table.SelectRows(#"PerformanceTable", each List.Contains(ExcelTable[VENDOR], [VENDOR_CODE]))
in
Filter
Now I'm not sure if CurrentWorkbook
is usable in a power bi, so my question is how do I modify this to now filter the same query in Power BI using the same table (which will also be imported).现在我不确定
CurrentWorkbook
是否可用于 power bi,所以我的问题是如何修改它以现在使用同一个表(也将被导入)在 Power BI 中过滤相同的查询。
Okay, I figured this out as to what the syntax needs to be in order for this filter to work.好的,我想出了这个过滤器需要什么语法才能工作。 I couldn't use
CurrentWorkbook
because the Power BI report isn't a workbook;我无法使用
CurrentWorkbook
因为 Power BI 报告不是工作簿; however, you can refer to the Excel.Workbook
as long as you reference the location.但是,只要引用该位置,就可以引用
Excel.Workbook
。
The one area of improvement I'd like to do is refer to the workbook, not from it's location or drive (as that might change), but instead refer to it within the Power BI Report.我想要做的一个改进领域是引用工作簿,而不是从它的位置或驱动器(因为这可能会改变),而是在 Power BI 报告中引用它。
let
Source = Sql.Database("MyDatabase", "MY_DATA"),
#"PerformanceTable" = Source{[Schema="dbo",Item="PerformanceTable"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(#"PerformanceTable",{{"VENDOR_CODE", Int64.Type}}),
Excel1 = Excel.Workbook(File.Contents("C:\Users\myaccount\OneDrive\Power BI\Vendor List.xlsx"), null, true),
_Vendor_List_Table = Excel1{[Item="_Vendor_List",Kind="Table"]}[Data],
ExcelChange = Table.TransformColumnTypes(_Vendor_List_Table,{{"Vendor", Int64.Type}, {"Name", type text}, {"Group", type text}}),
Filter = Table.SelectRows(#"Changed Type", each List.Contains(ExcelChange[Vendor], [VENDOR_CODE]))
In
Filter
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.