Skip to content
Advertisement

Create custom field by subtracting column values from two different rows based on multiple IDs

I have to create custom column by subtracting column values from two different rows based on multiple IDs.

Data set is like below:

ID2 is different for each date. Now I have to display custom field like below:

Repeated for other ID2 also.

Please suggest how should I proceed. I tried using Cross Join but but not giving desirable result.

Advertisement

Answer

Try this:

You can add more logic in the final CONCAT in order to shape the results in different way. For example, if there is not next value to be get, you can leave the value NULL.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement