Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
We're creating some SQL views in a Lakehouse.
In particular customer need to process the moving total over 3 months. I was lookng at this: OVER Clause (Transact-SQL) - SQL Server | Microsoft Learn
But seems like Lakehouse doesn't support something like: ROWS BETWEEN 2 PRECEDING AND CURRENT ROW
full query:
Solved! Go to Solution.
Hi @debiagui ,
The `ROWS BETWEEN` syntax, commonly used for defining window frames in SQL Server, might not directly apply in the Lakehouse environment. This is because the SQL analytics endpoint in Lakehouse, while providing a rich set of functionalities for data analysis, does not support the full T-SQL surface area, including certain windowing functions and syntaxes.
For calculating moving totals in Lakehouse, Here are a couple of suggestions:
Built-in Functions - Spark 3.5.1 Documentation (apache.org)
SELECT
A.ProductId,
A.MarketId,
A.MonthSeq AS MonthGrouping,
SUM(B.SalesAmount) AS MovingTotal
FROM
(SELECT
PRD.ProductId,
SO.MarketId,
CA.MonthSeq
FROM
SellOut AS SO
INNER JOIN
Product AS PRD ON SO.ProductId = PRD.ProductId
INNER JOIN
Calendar AS CA ON SO.Date= CA.Date
GROUP BY
PRD.ProductId,
SO.MarketId,
CA.MonthSeq) AS A
INNER JOIN
(SELECT
PRD.ProductId,
SO.MarketId,
CA.MonthSeq,
SO.SalesAmount
FROM
SellOut AS SO
INNER JOIN
Product AS PRD ON SO.ProductId = PRD.ProductId
INNER JOIN
Calendar AS CA ON SO.Date= CA.Date) AS B
ON
A.ProductId = B.ProductId AND
A.MarketId = B.MarketId AND
B.MonthSeq BETWEEN A.MonthSeq - 2 AND A.MonthSeq
GROUP BY
A.ProductId,
A.MarketId,
A.MonthSeq
ORDER BY
A.ProductId,
A.MarketId,
A.MonthSeq;
For more insights into the capabilities and limitations of the SQL analytics endpoint in Lakehouse, you might find the following documentation useful:
What is a lakehouse? - Microsoft Fabric | Microsoft Learn
If you have any other questions please feel free to contact me.
Best Regards,
Yang
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
Hi @debiagui ,
The `ROWS BETWEEN` syntax, commonly used for defining window frames in SQL Server, might not directly apply in the Lakehouse environment. This is because the SQL analytics endpoint in Lakehouse, while providing a rich set of functionalities for data analysis, does not support the full T-SQL surface area, including certain windowing functions and syntaxes.
For calculating moving totals in Lakehouse, Here are a couple of suggestions:
Built-in Functions - Spark 3.5.1 Documentation (apache.org)
SELECT
A.ProductId,
A.MarketId,
A.MonthSeq AS MonthGrouping,
SUM(B.SalesAmount) AS MovingTotal
FROM
(SELECT
PRD.ProductId,
SO.MarketId,
CA.MonthSeq
FROM
SellOut AS SO
INNER JOIN
Product AS PRD ON SO.ProductId = PRD.ProductId
INNER JOIN
Calendar AS CA ON SO.Date= CA.Date
GROUP BY
PRD.ProductId,
SO.MarketId,
CA.MonthSeq) AS A
INNER JOIN
(SELECT
PRD.ProductId,
SO.MarketId,
CA.MonthSeq,
SO.SalesAmount
FROM
SellOut AS SO
INNER JOIN
Product AS PRD ON SO.ProductId = PRD.ProductId
INNER JOIN
Calendar AS CA ON SO.Date= CA.Date) AS B
ON
A.ProductId = B.ProductId AND
A.MarketId = B.MarketId AND
B.MonthSeq BETWEEN A.MonthSeq - 2 AND A.MonthSeq
GROUP BY
A.ProductId,
A.MarketId,
A.MonthSeq
ORDER BY
A.ProductId,
A.MarketId,
A.MonthSeq;
For more insights into the capabilities and limitations of the SQL analytics endpoint in Lakehouse, you might find the following documentation useful:
What is a lakehouse? - Microsoft Fabric | Microsoft Learn
If you have any other questions please feel free to contact me.
Best Regards,
Yang
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!