I am currently working on a risk matrix in PowerBI which I want to create with Deneb. The goal is a 3x3 matrix that allows cross-filtering. David already gave create support regarding the Vega lite code, however, some PowerBI specific questions remain.
My current progress can be seen here: PowerBi File.
Now I face the following challenges, which I am grateful for any help in overcoming:
The selected cell should be highlighted (see sheet 2 as an example). As an alternative it would be nice if at least the selected number can be highlighted. With "__ selected__" I unfortunately did not reach the objective.
It would be nice if a 0 appeared in the empty field.
There should be a space between each cell comparable to the one on page 2.
As always, I appreciate any solutions, hints or ideas. :)
OK, follow these steps to have a fully working and interactive risk matrix like the one below.
Create a Damage dimension table as follows
Create an Exposure dimension table as follows:
Create two relationships to your fact table as follows.
Create a measure as follows
Risk Count = COUNTROWS(Sheet1) +0
Create a new Deneb visual adding the two dimensions and the measure (make sure not to aggregate)
Place this code inside Deneb
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {"name": "dataset"},
"width": 500,
"height": 500,
"encoding": {
"y": {
"field": "Exposure",
"type": "ordinal",
"sort": ["high", "medium", "low"]
},
"x": {
"field": "Damage",
"type": "ordinal",
"sort": ["low", "medium", "high"],
"axis": {"labelAngle": 0}
}
},
"layer": [
{
"encoding": {
"opacity": {
"condition": {
"test": {"field": "__selected__", "equal": "off"},
"value": 0.3
}
}
},
"mark": {
"type": "rect",
"color": {
"expr": "(datum['Exposure'] == 'high' & datum['Damage'] == 'high') || (datum['Exposure'] == 'high' & datum['Damage'] == 'medium') || (datum['Exposure'] == 'medium' & datum['Damage'] == 'high') ? 'red' : (datum['Exposure'] == 'medium' & datum['Damage'] == 'medium') || (datum['Exposure'] == 'high' & datum['Damage'] == 'low') || (datum['Exposure'] == 'low' & datum['Damage'] == 'high') ? 'orange': 'green'"
}
}
},
{
"mark": {
"type": "text",
"fontSize": 16,
"fontWeight": "bold",
"color": "white"
},
"encoding": {"text": {"field": "Risk Count", "type": "quantitative"}}
}
],
"config": {"axis": {"grid": true, "tickBand": "extent"}}
}
Related
I've been playing around with the Deneb visual in PowerBI Desktop and (amongst many other things) have been trying to create a simple column chart that shows negative values in red and positive values in green, however can't for the life of me seem to get it working - I believe the condition/test in my script is correct, but it refuses to 'fire' when it's 'true'
I've read through the condition page of the Vega-Lite documentation https://vega.github.io/vega-lite/docs/condition.html and have a condition section within the encoding/color
I've added Month End and MonthYear columns from my Calendar table and an EBITDA measure from a fact table to the Deneb visual
Month End
MonthYear
EBITDA
31/7/2021
"Jul-21"
8277.56
31/8/2021
"Aug-21"
-15123.66
30/9/2021
"Sep-21"
9502.11
31/10/2021
"Oct-21"
13090.99
{
"data": {"name": "dataset"},
"mark": "bar",
"encoding": {
"x": {
"field": "MonthYear",
"sort": {"field": "Month End"}
},
"y": {
"field": "EBITDA",
"aggregate": "sum"
},
"color": {
"condition": {
"test": "datum['EBITDA']<0",
"value": "red"
},
"value": "green"
}
}
}
If I adjust the condition to be "test": "1==1" then the 'true' path works, so I assume I've got something wrong with my test line, though this seems to be correct per a lot of blogs, stackoverflow questions etc.
I've also tried using a "tranform:" channel to create a new Neg field in the Deneb dataset and referring to that field in my test, but it still won't adjust the colour.
It doesn’t like your aggregation. It looks like the data you are sending in is already aggregated by Power BI. If so, this will work:
"y": {
"field": "b",
"type": "quantitative"
},
View sample in the Vega Editor
If your data isn’t aggregated, add an aggregate transform like this:
"transform": [
{"aggregate": [{
"op": "sum",
"field": "b",
"as": "bsum"
}],
"groupby": ["a"]}
],
"mark": "bar",
"encoding": {
"x": {
"field": "a",
"sort": {"field": "a"}
},
"y": {
"field": "bsum",
"type": "quantitative"
},
"color": {
"condition": {
"test": "datum['bsum']<0",
"value": "red"
},
"value": "green"
}
}
}
Open the Chart in the Vega Editor
I have a data below:
xmin xmax ymin ymax
2 4 1 2
4 6 2 3
I wanted to generate a shape which I can use to fill in values. Please assist.
Thank you
Create your data like this.
Make sure every column says do not aggregate.
Import the Deneb visual from marketplace.
Add the fields to the Deneb visual well as follows:
Paste the following code into Deneb.
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"width": 300,
"height": 240,
"background": "white",
"data": {"name": "dataset"},
"layer": [
{
"mark": {"type": "rect", "color": "#9bc2e6"}
}
],
"encoding": {
"x": {
"field": "xmin",
"type": "quantitative",
"scale": {"domain": [0, 10]}
},
"x2": {"field": "xmax"},
"y": {
"field": "ymin",
"type": "quantitative",
"scale": {"domain": [8, 0]}
},
"y2": {"field": "ymax"},
"color":{"field": "id"}
}
}
That's it.
OBJECTIVE
I'm trying to add data labels to my chart, however I have multiple bars layered on top of each other, and I need the data labels to hover over different bars depending on if values in a certain field are positive or negative.
ATTEMPT
This could be achieved by changing the "field" property of the "y" encoding using a condition. I've spent some time exploring Vega-Lite documentation and experimenting with some stuff, but I can't get it to work no matter what I try. Vega seems to ignore by condition. I'm also curious if I'm able to apply conditions to "mark" rather than "encoding". When values are negative, I'd like to change "dy" to 10 from -10.
Any suggestions?
'''
"mark": {
"type":"text",
"dy":-10
},
"encoding": {
"text": {
"field": "field_one"
},
"y": {
"condition":{
"test":"datum['test_data'] < 0",
"field": "field_one"
},
"field": "field_two"
}....
}
'''
A couple solutions exist.
Two Text Encodings:
One solution is to create two texts with varying y offsets and fields, and hide them depending on whether the values are positive or negative.
{
"mark": {
"type":"text",
"dy":-10
},
"encoding": {
"text": {
"condition":{
"test": "datum['test_data'] >= 0",
"type":"quantitative",
"field": "test_data"
}
"value": ""
},
"y": {
"field": "field_one",
"type": "quantitative"
}
}
},
{
"mark": {
"type":"text",
"dy":10
},
"encoding": {
"text": {
"condition":{
"test": "datum['test_data'] < 0",
"type":"quantitative",
"field": "test_data"
}
"value": ""
},
"y": {
"field": "field_two",
"type": "quantitative"
}
}
}
Transformation and Calculation
The other solution only solves the "dy" problem and was answered using another technique involving transform and calculate on GitHub.
I am using Deneb custom visual to repeat visual for different tasks. Is it possible to only show the relevent Y-axis values. Following data is used:
The following Vega-lite JSON is used:
{
"data": {"name": "dataset"},
"mark": {
"type": "bar",
"opacity": 1,
"tooltip": true,
"cornerRadius": 15
},
"encoding": {
"x": {
"field": "Earliest StartDate",
"type": "temporal"
},
"y": {
"field": "MachGrpCode",
"type": "nominal",
"axis": {
"title": null,
"grid": true,
"tickBand": "extent"
}
},
"row": {
"field": "ProdHeaderOrdNr",
"header": {"labelAngle": 0}
}
},
"resolve": {
"axis": {
"x": "independent",
"y": "independent"
}
}
}
Which results in:
Is it possible to only use the relevent task values (for 022 --> erase 6700 row)?
From what I've seen, this is a Vega bug. The recommended work-around is to use vconcat with a filter transform. If you only have a few ProdHeaderOrdNr, this is doable.
Open the Chart in the Vega Editor
I am trying to define a custom theme for my Power BI reports. I have been able to 'show' the border and set the color by importing the theme JSON. I cannot find out how to define the corner radius in the custom JSON file. Here is what I've tried:
{
"name": "Radius Theme",
"tableAccent": "#284861",
"visualStyles": {
"*": {
"*": {
"border": [{
"show": true,
"radius": "5D",
"color": { "solid": { "color": "#00FF00" } }
}]
}
}
}
}
Trying to reverse engineer, using the Power BI Desktop editor, I setup one visualization with rounded corners and saved the PBIX. When I crack open the PBIX file and check out the Layout contents, I see the following the appears to define the visualization border properties with a radius of '10D', just like I set in the UI.
"border": [
{
"properties": {
"show": {
"expr": {
"Literal": {
"Value": "false"
}
}
},
"radius": {
"expr": {
"Literal": {
"Value": "10D"
}
}
},
"color": {
...
Remove the quotes and the "D" from the radius value and it will work.
"border": [{
"show": true,
"radius": 10,
"color": { "solid": { "color": "#00FF00" } }
}],