jsonpowerbivegasankey-diagramdeneb

Integrating PowerBI Measures into Deneb Vega Visualisation (David Deneb Sankey)


I've been trying to modify the Sankey Chart made by @davidebacci to utilise in PowerBI / Deneb.

The template he has shared is beautiful. However, all of the values have been manually placed into the visualisation template.

I've modified the categories / stacks / sorting / gaps etc. myself to suit my requirements (I intend to use this for emergency department data to show how many arrive by either Ambulance or Self Presentation, and then from all those arrivals which are admitted, discharged, transferred, and then the final stack being more information on those outcomes).

My data section currently looks like this for the stacks (abbreviated):

` "data": [ { "name": "input", "values": [

 // ... Stack One
  
    {
      "category": "EMS",
      "stack": 1,
      "sort": 1,
      "labels": "left"
    },
    {
      "category": "Self",
      "stack": 1,
      "sort": 2,
      "labels": "left",
      "gap": 20
    },
    
 // ... Stack Two       
    
    {
      "category": "Arrivals",
      "stack": 2,
      "sort": 1,
      "labels": "left"
    },
    
    
 // ... Stack Three 
    
    {
      "category": "Discharge",
      "stack": 3,
      "sort": 1,
      "labels": "left"
    },`

And then later I've done the routing in the same "data" section (abbreviated again):

` // ... Routing Stack 1

    {"source": "EMS", "destination": "Arrivals", "value": 2437},
    {"source": "Self", "destination": "Arrivals", "value": 5673},
    
 // ... Routing Stack 2
    
    {"source": "Arrivals", "destination": "Discharge", "value": 7366},
    {"source": "Arrivals", "destination": "Admission", "value": 672},
    {"source": "Arrivals", "destination": "Transfer", "value": 72},`

Placing the JSON in Deneb, the visualisation works perfectly. However, I would now like the values for the routing to change each month as the data updates, without having to go in and manually update the values.

I've created measures such as below in DAX which are calculating the necessary values, and I've added those into the Deneb values - I can see them in the Data Pane at the bottom with the correct values, so the measure itself is working as intended. There is a measure created for each of the required routes between stacks.

ems_arrivals = CALCULATE( SUM('arrivals'[count]), 'arrivals'[admit_type_grouped] = "EMS" )

I'm having problems with how to update the "value" in the routing part to utilise these values as opposed to the manual values.

So first of all I just tried simply changing "value": to "ems_arrivals".

{"source": "EMS", "destination": "Arrivals", "value": "ems_arrivals"},

When I do this, the visualisation continues to work for the manually entered field, but the one I've updated now no longer appears.

I also tried adding it to the "signals" section - no success.

I've got a feeling that the issue is related to this part of the JSON.

"data": [ { "name": "input",

The data table is called "input" but am I right in thinking the data I've added from PowerBI measures will be populated in "dataset"? So when I'm putting "ems_arrivals" into "input", it can't find anything? Honestly, the later code is way out of my skillset to modify.

Any help appreciated - to summarise, the visualisation works brilliantly with the stacks, categories, sorts, labels, gaps all manually defined, and I'm happy to leave those manually defined - I would just like to use PowerBI measures to update the values.


Solution

  • Glad you like it. Follow these steps.

    Delete the values from the spec so you have code like this (I added a new dataset called "dataset")

    enter image description here

    Create MyData table with columns like this: enter image description here

    Ensure the blank cells are null.

    Add all columns to the visual.

    enter image description here

    Make one change to ensure the sort is correct in the domain:

    enter image description here

    enter image description here

    You can now replace any of your columns with a measure of the exact same name.