Original request
$sql = "SELECT date, val1, val2, val3 FROM `$table` ORDER BY date ASC"; You need to make a query similar to the original with 3 additional virtual columns containing previous values (if any), something like this:
$sql2 = "SELECT date, val1, val2, val3, prev_val1, prev_val2, prev_val3 FROM `$table` ORDER BY date ASC"; OR more ideally, a query containing the difference between the current value and the previous value.
$sql3 = "SELECT date, (val1 - prev_val1) AS val12, (val2 - prev_val2) AS val22, (val3 - prev_val3) AS val32 FROM `$table` ORDER BY date ASC"; If the cells contain values, they are integer. NULLs may be missing or equal to 0. NOT negative.