
There is a blog about running QTD and YTD that is posted by @Sefan_Linders
My customer wants to implement this on top of flipping sign functionality that I posted earlier.
To achieve this, I tried to implement the solution and used a Large Language Model (LLM) for optimizing the SQL statement. The LLM suggested that using window functions is more efficient than using subqueries or self-joins, as it improves readability and allows calculations without altering the query structure.
Here is the optimized SQL query provided by the LLM:
SELECT ACCT, Date, Version, CostCenter, Amount,
SUM(Amount) OVER (PARTITION BY ACCT, CostCenter ORDER BY Date ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS YTD,
SUM(Amount) OVER (PARTITION BY ACCT, CostCenter, YEAR(Date), QUARTER(Date) ORDER BY Date ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS QTD
FROM Fact
ORDER BY ACCT, CostCenter, Date, Version.
I hope this helps someone who wants to implement QTD and YTD in SAP Datasphere.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
25 | |
24 | |
17 | |
14 | |
10 | |
9 | |
9 | |
7 | |
7 | |
7 |