How to take the difference from a row with the condition to the rest


#1

I want to convert a table below. Want to take the difference from the lastest rank in group 2 of each product to the first row from group 2 in each product as growth
Product, group, rank, val
|a|1|1|Null|
|a|1|2|Null|
|a|2|1|10|
|a|2|2|11|
|a|2|3|20|
|a|3|1|null|
|a|3|2|null|
|b|1|1|null|
|b|1|2|null|
|b|2|1|35|
|b|2|2|33|
|b|2|3|50|
|b|3|1|null|
|b|3|2|null|

To

product group rank Val Growth
a 1 1 Null null
a 1 2 Null null
a 2 1 10 null
a 2 2 11 null
a 2 3 20 10
a 3 1 null null
a 3 2 null null
b 1 1 null null
b 1 2 null null
b 2 1 35 null
b 2 2 33 null
b 2 3 50 15
b 3 1 null null
b 3 2 null null