I've created a Deneb bar chart, and I would like to apply a diffrent color to the bars based on a DAX measure in Power BI.
For instance, if the value is greater than 200, I want the bar to be red, otherwise green.
I'm not sure how to do this, I've written an expression insde the mark argument but it doesn't work, all the bars look red. I'd be really greatful if you could advide me on how to fix this.
{
"title": {"text": "Simple Bar chart - expression", "fontSize": 14, "anchor": "start", "align": "left"},
"data": {"name": "dataset"},
"mark": {"type": "bar", "fill":{"expr": " 'Measure1' > '200'? 'red':'green' "}},
"encoding":
{
"y": {
"field": "Site Name", "type": "nominal",
"axis": {"title": null},
"sort": {"field": "Measure1", "order": "descending"} },
"x": {"field": "Measure1", "type": "quantitative"
}
}
}
Does this work for you?
{
"title": {
"text": "Simple Bar chart - expression",
"fontSize": 14,
"anchor": "start",
"align": "left"
},
"data": {"name": "dataset"},
"mark": {
"type": "bar",
"fill": {
"expr": " datum.Measure1 > 200? 'red':'green' "
}
},
"encoding": {
"y": {
"field": "Site Name",
"type": "nominal",
"axis": {"title": null},
"sort": {
"field": "Measure1",
"order": "descending"
}
},
"x": {
"field": "Measure1",
"type": "quantitative"
}
}
}