# Query on stacked bar graph

**URL:** <https://community.grafana.com/t/query-on-stacked-bar-graph/150112>\
**Category:** Dashboards\
**Tags:** stacking, bar-chart\
**Created:** [May 10, 2025, 3:49pm UTC](https://community.grafana.com/t/query-on-stacked-bar-graph/150112 "2025-05-10T15:49:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpraok](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/jpraok/32/53917_2.png) [@jpraok](https://community.grafana.com/u/jpraok)\
**Post date:** [May 10, 2025, 3:49pm UTC](https://community.grafana.com/t/query-on-stacked-bar-graph/150112/1 "2025-05-10T15:49:11Z")

</div>

I am using grafana version 11.6 on linux machine

I want to show category wise sales on daily basis, I use postgreSql table (sales\_summary) with 3 columns as data source.  
sales\_date  
category  
sales\_amount.

I want to show this data in a stacked bar graph, where x-axis contain sales\_date and y-axis contains sum of all sales\_amount for each day. The bar should be stacked based on sales category.

I am trying to use the below query  
SELECT DATE(sales\_date), category, SUM(sales\_amount) FROM sales\_summary  
GROUP BY DATE(sales\_date), category  
ORDER BY DATE(sales\_date)

This does not show colored stack, but shows 2 bars for 2 categories both bars has same x-axis date.  
I want to see them as one bar with 2 colors for 2 categories for single date.

Please let me know how can I achieve this

---

<div class="post-metadata">

**Author:** ![dawiddebowski](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/dawiddebowski/32/49435_2.png) [@dawiddebowski](https://community.grafana.com/u/dawiddebowski)\
**Post date:** [May 10, 2025, 5:57pm UTC](https://community.grafana.com/t/query-on-stacked-bar-graph/150112/2 "2025-05-10T17:57:08Z")

</div>

Hi,

Can you share a screen of how it looks now? From the description I would tell you need to change the `Stacking` option to normal and it should work, but it might not (depending on the data you have now).

 ![Zrzut ekranu 2025-05-10 o 19.55.57](https://us1.discourse-cdn.com/grafana/original/3X/b/1/b188bca8a28fe4815208e25ab3a2460bef0bbe1e.png)

If it doesn’t work can you share some sample of the data (preferably as a table - you can obtain that by toggling Table View above the chart).

---

<div class="post-metadata">

**Author:** ![jpraok](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/jpraok/32/53917_2.png) [@jpraok](https://community.grafana.com/u/jpraok)\
**Post date:** [May 11, 2025, 4:23pm UTC](https://community.grafana.com/t/query-on-stacked-bar-graph/150112/3 "2025-05-11T16:23:51Z")

</div>

Yes. I have done stacking as “Normal”

Below is the sample data :  
sale\_date category sales\_amount  
08-02-2025 A 506  
08-02-2025 B 106  
08-02-2025 B 409  
09-02-2025 A 138  
09-02-2025 B 235  
11-02-2025 A 169  
12-02-2025 A 667  
12-02-2025 B 736  
12-02-2025 A 350  
12-02-2025 A 368  
13-02-2025 B 210  
13-02-2025 B 101  
13-02-2025 B 132  
14-02-2025 B 107  
14-02-2025 A 217  
15-02-2025 A 101  
15-02-2025 A 119

I am expecting one bar with x-axis value as “08-02-2025” with y-axis value as 1021 (506+106+409) as has 2 colors first color till 506 and second color for 505.

Now it is showing in single color.

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/8/8/881e4cf59ac2f507d39c40109ca108cf5e3ecc49.png)

---

<div class="post-metadata">

**Author:** ![dawiddebowski](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/dawiddebowski/32/49435_2.png) [@dawiddebowski](https://community.grafana.com/u/dawiddebowski)\
**Post date:** [May 11, 2025, 6:16pm UTC](https://community.grafana.com/t/query-on-stacked-bar-graph/150112/4 "2025-05-11T18:16:41Z")

</div>

Is the data you’ve provided raw from database or is it seen in Grafana query (as far as I know SQL, you shouldn’t have two different 08-02-2025 B values). If that’s the case, your data in Grafana should look like this:  
08-02-2025 A 506  
08-02-2025 B 515  
09-02-2025 A 138  
09-02-2025 B 235  
11-02-2025 A 169  
12-02-2025 A 1385  
12-02-2025 B 736  
13-02-2025 B 443  
14-02-2025 B 107  
14-02-2025 A 217  
15-02-2025 A 220

Is that right (when toggling the Table View in Grafana)?  
If so, what you need is transform the data to a matrix (the first transformation on the screen below). I also included the convert field type transformation but in your case it might not be needed.

 ![Zrzut ekranu 2025-05-11 o 20.15.43](https://us1.discourse-cdn.com/grafana/original/3X/d/9/d9ed33f2bb79c9a965d6c72f590ce34c942edbc7.png)

---

<div class="post-metadata">

**Author:** ![jpraok](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/jpraok/32/53917_2.png) [@jpraok](https://community.grafana.com/u/jpraok)\
**Post date:** [May 12, 2025, 3:13am UTC](https://community.grafana.com/t/query-on-stacked-bar-graph/150112/5 "2025-05-12T03:13:22Z")

</div>

Thank you. I will try this too. But my data is correct. I will have multiple sales amount for same day and same category. I need to sum them up based on date and category
