0

I have a table with the values that I want to display on Power BI Deneb Bar chart.

LossReason PrimaryQuantityLoss
Chupados 1
Generic Terminate 18530
Generic Terminate 929
Generic Terminate 980
Leitosas 1
Manchas 1

But the values are not aggregating Values stacked one above the others , the value displayed should be 20.439 instead of 18530/929/980 separated on the same bar.

I'm using the following specification:

{
  "data": {"name": "dataset"},
  
  "layer":[{
      "mark": "bar"},
    {
      "mark": {"type": "text", "color": "black", "xOffset": 8},
        "encoding": {
          "text": {"field": "PrimaryQuantityLoss", "type": "quantitative"}}
    }]
  ,
  
  "encoding": {
    "x": {
      "field": "PrimaryQuantityLoss",
      "type": "quantitative"
    },
    "y": {
      "field": "LossReason",
      "type": "ordinal"
    }
  }
}

I tried to do an aggregate by sum, but doesn't worked.

Faria
  • 3
  • 1
  • Hello @Faria, values are not aggregating because you added `LossReason` in Y axis. It like you're doing `Group By` – Dordi Jun 13 '23 at 15:39

1 Answers1

0

Change "PrimaryQuantityLoss" to "Sum of PrimaryQuantityLoss". As below, we can do it manually.


(1) Go to Visualizations > Values > "PrimaryQuantityLoss" and select Sum.

enter image description here

(2) Then a message window will appear to set the Field. Select Sum of PrimaryQuantityLoss as newly assigned field.

enter image description here

(3) Done. You will notice that the text encoding and the x-field are both renewed.

enter image description here

New specification is:

{
  "data": {"name": "dataset"},

  "layer":[{
      "mark": "bar"},
    {
      "mark": {"type": "text", "color": "black", "xOffset": 8},
        "encoding": {
          "text": {"field": "Sum of PrimaryQuantityLoss", "type": "quantitative"}}
    }]
  ,

  "encoding": {
    "x": {
      "field": "Sum of PrimaryQuantityLoss",
      "type": "quantitative"
    },
    "y": {
      "field": "LossReason",
      "type": "ordinal"
    }
  }
}
Kazuhito
  • 440
  • 3
  • 7