I have a data set with one measure, and two categories (Month, Product). What I want to achieve is the following view in a data module:
I want to have a column which shows me the value of Month-1 based on Month in Column Month
(e.g. May 2023 -> Value from April 2023)
| Product | Month | Measure | Calculation (measure from month -1) |
|---|---|---|---|
| A | 4 | 15 | - |
| A | 5 | 23 | 15 |
| A | 6 | 20 | 23 |
Is there an easy code for that or do I need to work with joins and support columns?
I tried already all sorts of Total,Aggregate functions with FOR, PERIOD clauses. I don't want to work with current_timestamp. Formatting is not an issue, as it is recognized as the correct data type.
So what you're looking for in SQL would be:
You can probably set a default (like
'-') to replaceNULL. It may depend upon which RDBMS you are using.You can do that in a Cognos data set in a couple of ways.
LAG().NULLor'-'as desired. (like identifying where this and previous rows have a different Product.)Be sure to schedule the data module to refresh on a schedule.
The second method will run slower because you're running the query twice and having Cognos do all of the work. The advantage is it is developed fully using native Cognos features. Also, you may be able to use the same concepts to perform this all within the data module