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.
Change "PrimaryQuantityLoss"
to "Sum of PrimaryQuantityLoss"
. As below, we can do it manually.
(1) Go to Visualizations > Values > "PrimaryQuantityLoss" and select Sum
.
(2) Then a message window will appear to set the Field. Select Sum of PrimaryQuantityLoss
as newly assigned field.
(3) Done. You will notice that the text encoding and the x-field are both renewed.
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"
}
}
}