Hi @markusbuecher97 and welcome to the Grafana forum.
What you describe is possible, but I only know how to do it using Flux (not InfluxQL). Are you willing to perhaps set up a test system that you could configure with Flux and try it out there? Not sure how many other queries you have built over the past year (and thus how complicated converting everything would be).
Here is the query for how to select the number of days in the time range: