It looks like you are using Prometheus, which I have zero experience with. You are also using a fairly old version of Grafana, so I would suggest you upgrade to the latest version.
Once you do, you will have the ability to do a variety of transformations. It sounds like one of the many transformations will do exactly what you want. From the docs:
Transformations process the result set of a query before it’s passed on for visualization. They allow you to rename fields, join separate time series together, do math across queries, and more. For users, with numerous dashboards or with a large volume of queries, the ability to reuse the query result from one panel in another panel can be a huge performance gain.
The transformations feature is accessible from the Transform tab of the Grafana panel editor.
Transformations sometimes result in data that cannot be graphed. When that happens, click the
Table view toggle above the visualization to switch to a table view of the data. This can help you understand the final result of your transformations.