Please help me understand how tables in the database refer to the statistics!

I got myself a p1 sensor last month, but by some misconfiguration in the energy dashboard I lost my data.
Luckily I could export the data from my energy app, so I thought I’d just import the historic data.

I thought I’d start with gas as we only use it for the stove and the numbers don’t continuously go up, dropped the rows from statistics and statistics_short_term and used spooks import statistics feature to import the data (including the meter reading before I installed the sensor).

- start: "2023-12-18 14:00:00+01:00"
  state: 161.684
  sum: 161.684
- start: "2023-12-18 19:00:00+01:00"
  state: 161.781
  sum: 0.097
  ...
- start: "2024-01-12 21:00:00+01:00"
  state: 164.13
  sum: 0.053
- start: "2024-01-14 14:00:00+01:00"
  state: 164.147
  sum: 0.017

When I took a look at the database they were perfectly imported as I had provided them.

But when I looked at the Energy tab it looked like this (with many negative values)

At first I tried to fix the readings using adjust statistic in Developer Tools, but that only messed up the readings in the database even more and of course tries to correct the readings every hour with incorrect data.

Can someone please help me see what I’m missing here?
This is the 3rd day now I’m fighting this issue and am about to give up on it.