Need to generate a customized column on basis of 2 conditions

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Need to generate a customized column on basis of 2 conditions

praskumar
I have data like
opp_num risk_code model_date
2725072 Highest Risk 10/3/2016
2725072 Med Risk 1/23/2017
2725072 Med Risk 1/30/2017
2725072 Med Risk 2/6/2017
2725072 Med Risk 2/13/2017
2725072 Med Risk 3/7/2017
2725072 High Risk 3/13/2017
2725072 High Risk 3/21/2017
2725072 Highest Risk 3/28/2017
2725072 Med Risk 4/3/2017
2725072 High Risk 4/9/2017
2725072 Med Risk 4/18/2017
2725072 High Risk 4/24/2017
2725072 High Risk 5/1/2017
2725072 High Risk 5/1/2017
2731759 Low Risk 1/23/2017
2731759 Med Risk 1/30/2017
2731759 High Risk 3/7/2017
2731759 Med Risk 3/13/2017
2731759 Med Risk 3/21/2017
2731759 High Risk 4/9/2017
2731759 High Risk 4/18/2017
2731759 Med Risk 4/24/2017
2731759 High Risk 5/1/2017
2731759 High Risk 5/1/2017


My requirement is whenever risk_code changes from one risk to other, a hard coded value (14) should decrease from 14 to 13, and also when opp_num changes, it should take the first value (14) and same process to follow..

Please guide me on how to implement this requirement. I wrote for condition and 2 if loops but i didnt get desired result

My result should like
opp_num risk_code model_date
2725072 Highest Risk 10/3/2016 14
2725072 Med Risk 1/23/2017 13
2725072 Med Risk 1/30/2017 13
2725072 Med Risk 2/6/2017 13
2725072 Med Risk 2/13/2017 13
2725072 Med Risk 3/7/2017 13
2725072 High Risk 3/13/2017 12
2725072 High Risk 3/21/2017 12
2725072 Highest Risk 3/28/2017 11
2725072 Med Risk 4/3/2017 10
2725072 High Risk 4/9/2017 9
2725072 Med Risk 4/18/2017 8
2725072 High Risk 4/24/2017 7
2725072 High Risk 5/1/2017 7
2725072 High Risk 5/1/2017 7
2731759 Low Risk 1/23/2017 14
2731759 Med Risk 1/30/2017 13
2731759 High Risk 3/7/2017 12
2731759 Med Risk 3/13/2017 11
2731759 Med Risk 3/21/2017 11
2731759 High Risk 4/9/2017 10
2731759 High Risk 4/18/2017 10
2731759 Med Risk 4/24/2017 9
2731759 High Risk 5/1/2017 8
2731759 High Risk 5/1/2017 8

Please help me