Search code examples
powerbivega-litedeneb

How to set the domain from to the sum of a field to the sum of another field?


I would like to calculate the sum of "SUM A" to set this as minimum scale value for all "X" axis. And the sum of "SUM B" to set als maximum scale for all "X" axis.

I can´t get my head around how to calculate the sum of the rows and use them in the "domain".

Hope the edit and example makes it more understandable.

I'm sorry if my first attempt to phrase the question wasn't clear.

{
  "data": { "values":[
{"EBENE_1": "A",    "EBENE_2":  "A",    "EBENE_3":  "A",    "EBENE_4":  "A" ,   "SUM A":    -70 ,   "SUM B":    41  },
{"EBENE_1": "A",    "EBENE_2":  "A",    "EBENE_3":  "B",    "EBENE_4":  "B" ,   "SUM A":    -22 ,   "SUM B":    81  },
{"EBENE_1": "A",    "EBENE_2":  "B",    "EBENE_3":  "C",    "EBENE_4":  "C" ,   "SUM A":    -31 ,   "SUM B":    89  },
{"EBENE_1": "A",    "EBENE_2":  "B",    "EBENE_3":  "D",    "EBENE_4":  "D" ,   "SUM A":    -28 ,   "SUM B":    8   },
{"EBENE_1": "A",    "EBENE_2":  "C",    "EBENE_3":  "E",    "EBENE_4":  "E" ,   "SUM A":    -39 ,   "SUM B":    55  },
{"EBENE_1": "A",    "EBENE_2":  "C",    "EBENE_3":  "E",    "EBENE_4":  "F" ,   "SUM A":    -78 ,   "SUM B":    78  },
{"EBENE_1": "A",    "EBENE_2":  "C",    "EBENE_3":  "F",    "EBENE_4":  "G" ,   "SUM A":    -99 ,   "SUM B":    88  },
{"EBENE_1": "A",    "EBENE_2":  "C",    "EBENE_3":  "F",    "EBENE_4":  "H" ,   "SUM A":    -85 ,   "SUM B":    67  }
]
},
"facet": {
    "row": {
      "field": "EBENE_1",
      "header": {"labelAngle": 0, "title": null, "labelAnchor": "start", "labelLimit": 50},
      "type": "nominal"
    }
  },
  "spec": {
    "hconcat": [
      {
        "height": 10,
        "mark": {"type": "bar"},
   "encoding": {
    "x": {"field": "SUM A", "aggregate": "sum"},
    "y": {"field": "EBENE_1", "title": null}}
      },
      {
        "facet": {
          "row": {
            "field": "EBENE_2",
      "header": {"labelAngle": 0, "title": null, "labelAnchor": "start", "labelLimit": 50},
            "type": "nominal"
          }
        },
        "spec": {
          "hconcat": [
            {
              "height": 10,
              "mark": {"type": "bar"},
   "encoding": {
    "x": {"field": "SUM A", "aggregate": "sum"},
    "y": {"field": "EBENE_2", "title": null}}
            },
            {
              "facet": {
                "row": {
                  "field": "EBENE_3",
      "header": {"labelAngle": 0, "title": null, "labelAnchor": "start", "labelLimit": 50},
                  "type": "nominal"
                }
              },
              "spec": {
                "hconcat": [
                  {
                    "height": 10,
                    "mark": {
                      "type": "bar"
                    },
   "encoding": {
    "x": {"field": "SUM A", "aggregate": "sum"},
    "y": {"field": "EBENE_3", "title": null}}
                  },
                  {
                    "facet": {
                      "row": {
                        "field": "EBENE_4",
      "header": {"labelAngle": 0, "title": null, "labelAnchor": "start", "labelLimit": 50},
                        "type": "nominal"
                      }
                    },
                    "spec": {
                      "hconcat": [
                        {
                          "height": 10,
                          "mark": {
                            "type": "bar"
                          },
   "encoding": {
    "x": {"field": "SUM A", "aggregate": "sum"},
    "y": {"field": "EBENE_4", "title": null}}
                        }
                      ]
                    }
                  }
                ]
              }
            }
          ]
        }
      }
    ]
  }
}

Solution

  • Another solution to my problem was suggested by the creator of Deneb, as there are at the moment problems using data expressions and repeat/concate/facet:

    {
      "data": {"name": "dataset"},
        "resolve": {
          "scale": {
            "x": "shared"
          }
      },
      "repeat": {
        "layer": ["STORNO", "EINGANG"],
        "column": [
          "EBENE_1",
          "EBENE_2",
          "EBENE_3",
          "EBENE_4"
        ]
      },
      "spec": {
        "height": 400,
        "width": 250,
        "mark": {"type": "bar"},
        "encoding": {
          "x": {
            "field": {"repeat": "layer"},
            "aggregate": "sum"
          },
          "y": {
            "field": {"repeat": "column"}
          }
        }
      }
    }