How to create a stack bar chart like a Excel Pivot in Grafana

I’m new to Grafana and I try to create a stacked bar chart with Grafana as I do it in MS Excel with the Pivot function. I’m using an MS SQL Server.

But I don’t know how to get the Datum and MaschineName values to the x- axis.
Here are my values:

Datum MaschineName Zustand Dauer
2023-02-06 M1 A 1
2023-02-06 M1 B 2
2023-02-06 M1 C 3
2023-02-06 M2 A 4
2023-02-06 M2 B 5
2023-02-06 M2 C 6
2023-02-07 M1 A 11
2023-02-07 M1 B 12
2023-02-07 M1 C 13
2023-02-07 M2 A 14
2023-02-07 M2 B 15
2023-02-07 M2 C 16

And my chart from Excel (that should also be the result with Grafana):

My SQL Code:
SELECT MaschineName, Zustand, Dauer, Datum as time FROM xxx

Thanks for your help