First add a header row above your data, on row 1, and have your data starting on row 2.
In cell C2, enter this formula:
In cell D2, enter this formula:
Fill each formula down across all your rows. You'll get this result:
Column C formula works by first checking if column B = "s", then it searches (
lookup) column B upwards for the previous instance of "s", and then uses the row number of that instance (
indirect) to reference the date relating to it, and performs the date sum. The column D formula does the same except matches with anything other than "s".
The first instance of "s" in col C, and the first instance of "non-S" in col D, will result in errors (because no previous data) so the formulas are surrounded by
iferror functions, which change the #N/A error result into a cleaner n/a string (cells C4 and D2).
If your data doesn't start at the top left
If your data does not start on row 2, still paste the above formulas in where I say and then copy and paste them to where they should be on your sheet, and most of the row references will update accordingly - you'll just need to change instances of
$1: to match your header row (e.g. if your header row is 25 then instances of
$1: would become
$25:). If your data does not start in column A then you will need to manually change the column letters accordingly in the formulas. For example if your data starts in column F then change every instance of
F, and every instance of