简体   繁体   English

基于 Excel 表筛选一个 Power BI 查询

[英]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.

相关问题 将excel查询复制到power bi - Copying excel query to power bi Power BI/Power Query:根据另一张工作表中的条件增加一张工作表中的最高数字 - Power BI/ Power Query: increment the highest number in one sheet based on conditions in another sheet 强大的查询功能可基于Excel列列表过滤SQL视图 - Power Query to Filter a SQL view based on an Excel column list Power Bi:导入没有表格的Excel工作表 - Power bi: Importing excel sheet with no table Excel-强大查询-如何基于现有查询创建新查询 - Excel - Power Query - how to create a new query based on the existing one 如何使用 Excel 表中的命名日期来过滤 Power Query? - How to use named date from table in Excel to filter Power Query? Power BI或Excel-如何基于数据透视表中的列添加自定义列 - power BI or Excel - How to add a custom column based on columns in the pivot table 根据不同列中的值创建一个表,显示 1 列中的所有值对组合 - Excel / Power BI - Creating a Table Showing All Pair Combinations of Values in 1 Column Based on Values in a Different Column - Excel / Power BI 如何根据表中的一系列值过滤 Power Query? - How to filter Power Query based off of a range of values in a table? 如何在电源查询(Excel 或 Power BI)中获取最近 4 周的日期 - How to get last 4 weeks dates in power query (Excel or Power BI)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM