简体   繁体   English

在 Power BI 中使用递归 CTE

[英]Using Recursive CTEs in Power BI

Power BI has some limitations on Direct queries that has proved a hurdle for me to work around; Power BI 对直接查询有一些限制,这对我来说是一个障碍; when using direct Query Power BI takes any query that you input and adds a使用直接查询时,Power BI 接受您输入的任何查询并添加一个

Select * From(

statement to the beginning of the code, which prevents the running of any stored procedure, declaring variables, or use CTE Expressions to create temporary/derived tables.声明到代码的开头,以防止运行任何存储过程、声明变量或使用 CTE 表达式创建临时/派生表。

I pulled the Stored Procedure Code out of the procedure, but i cannot figure out how to convert the whole statement from a CTE Expression to a derived expression.我从过程中提取了存储过程代码,但我无法弄清楚如何将整个语句从 CTE 表达式转换为派生表达式。 Does anyone know how to covert the query?有谁知道如何隐藏查询? i have only had success with the first select statement, but doing so prevents the Union, the Inner Join, and the relationship given between the two select Statements.我只在第一个 select 语句中取得了成功,但这样做会阻止联合、内部连接以及两个 select 语句之间给出的关系。

Original Procedure原始程序

WITH MaterialsTree(PartNo,SubPartNo,Descrip,Qty,Unit,Purchased,Vendor,TotalQty,UnitCost,UnitPrice,TotalCost,TotalPrice,TotalWt,
      StepNo,PartWt,Materials_ID,ItemNo, ParentID) AS 
(
    SELECT PartNo,SubPartNo,Descrip,Qty,Unit,Purchased,Vendor,TotalQty,UnitCost,UnitPrice,TotalCost,TotalPrice,TotalWt,
      StepNo,PartWt,Materials_ID,ItemNo, CAST(NULL AS INT) AS ParentID
        FROM Materials AS Mat
        WHERE PartNo = @PartNo
    UNION ALL
    SELECT m.PartNo,m.SubPartNo,m.Descrip,m.Qty,m.Unit,m.Purchased,m.Vendor,m.TotalQty,m.UnitCost,m.UnitPrice,m.TotalCost,m.TotalPrice,m.TotalWt,
      m.StepNo,m.PartWt,m.Materials_ID,m.ItemNo, t.Materials_ID AS ParentID
        FROM Materials AS m
        INNER JOIN MaterialsTree AS t 
            ON m.PartNo = t.SubPartNo
)
SELECT PartNo,SubPartNo,Descrip,Qty,Unit,Purchased,Vendor,TotalQty,UnitCost,UnitPrice,TotalCost,TotalPrice,TotalWt,
      StepNo,PartWt,Materials_ID,ItemNo, ParentID 
FROM MaterialsTree

I converted the Stored Procedure over to a Function;我将存储过程转换为 Function; this was allowed.这是允许的。 thank you for the guidance.谢谢你的指导。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM