Power BI has some limitations on Direct queries that has proved a hurdle for me to work around; when using direct Query Power BI takes any query that you input and adds a
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.
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. 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.
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