I want to create a calculated column based on a shared column but the calculated column should "restart" and be grouped based on a third column.
As described in the picture below Column 1 contains information belonging so a certain entity (some sort of ID). Column 2 contains the number of records that exists (1, 2 and 3). Column 3 contains the actual data (A, B or C) but the same value can exist between the three different records (separated by Column 2).
My previous process was discussed in this thread but as I went along I believe that it wasn't originally explained correctly.
Is there a way to create my desired result?
Use windowing function
DENSE_RANK()
with anOVER()
clause:The
PARTITION BY
will re-start the counter for each new value incolumn1
, while theORDER BY
defines the ranking.Hint: Do not paste pictures!
For your next question please follow my example to create a stand-alone example reproducing your issue and add the code you've tried yourself.