cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jonespossibly
Helper I
Helper I

Deneb Vega-lite trend line based on aggregated mark

I've got a line chart in which i have a line that is aggregated by sum. I have a trend line based on regression which works fine for the none-aggregated data, but i would like it to show a trend line based on the points given by the aggregate.

here is my vega-lite specification - can someone help me out?:

  "data": {"name": "dataset"},
  "layer": [
    {
      "mark": {"type": "line"},
      "encoding": {
        "y": {
          "field": "Weekly Avg"
        },
        "color": {
          "field": "Loan Type",
          "scale": {
            "range": [
              "#4795CA",
              "#F9B96A",
              "#779E41",
              "#F54f0F",
              "#cfcfcf"
            ]
          }
        }
      }
    },
    {
      "mark": {"type": "line"},
      "encoding": {
        "y": {
          "field": "Weekly Avg",
          "aggregate": "sum"
        },
        "color": {"datum": "Total"}
      }
    },
    {
      "mark": {
        "type": "line",
        "strokeDash": [5, 5]
      },
      "transform": [
        {
          "regression": "Weekly Avg",
          "on": "W / C",
          "groupBy": "W / C"
        
        }
      ],
      "encoding": {
        "y": {
          "field": "Weekly Avg"
        },
        "color": {"datum": "Trend"}
      }
    }
  ],
  "encoding": {
    "x": {
      "field": "W / C",
      "timeUnit": "monthdateyear",
      "type": "ordinal",
      "axis": {"format": "%d/%m/%Y"}
    },
    "y": {
      "type": "quantitative",
      "axis": {"format": "~s"}
    }
  }
}

 #deneb #vega-lite

2 REPLIES 2
mahoneypat
Microsoft
Microsoft

This would be easier to help do with data. Please see this video on how to add your data into the json (or you can just provide link to your sample data).

(2) Getting Help With the Deneb Visual in Power BI - YouTube

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


ok, so I've set up test data and specification below - how do i base the trend line on the total?

{
  "data": {"values":[
 {
   "Weekly Avg": "2",
   "Type": "a",
   "WC": "2022-01-01 00:00:00"
 },
 {
   "Weekly Avg": "4",
   "Type": "b",
   "WC": "2022-01-01 00:00:00"
 },
 {
   "Weekly Avg": "23",
   "Type": "c",
   "WC": "2022-01-01 00:00:00"
 },
 {
   "Weekly Avg": "28",
   "Type": "a",
   "WC": "2022-01-08 00:00:00"
 },
 {
   "Weekly Avg": "22",
   "Type": "b",
   "WC": "2022-01-08 00:00:00"
 },
 {
   "Weekly Avg": "25",
   "Type": "c",
   "WC": "2022-01-08 00:00:00"
 },
 {
   "Weekly Avg": "42",
   "Type": "a",
   "WC": "2022-01-15 00:00:00"
 },
 {
   "Weekly Avg": "21",
   "Type": "b",
   "WC": "2022-01-15 00:00:00"
 },
 {
   "Weekly Avg": "17",
   "Type": "c",
   "WC": "2022-01-15 00:00:00"
 },
 {
   "Weekly Avg": "42",
   "Type": "a",
   "WC": "2022-01-22 00:00:00"
 },
 {
   "Weekly Avg": "11",
   "Type": "b",
   "WC": "2022-01-22 00:00:00"
 },
 {
   "Weekly Avg": "27",
   "Type": "c",
   "WC": "2022-01-22 00:00:00"
 },
 {
   "Weekly Avg": "22",
   "Type": "a",
   "WC": "2022-01-29 00:00:00"
 },
 {
   "Weekly Avg": "11",
   "Type": "b",
   "WC": "2022-01-29 00:00:00"
 },
 {
   "Weekly Avg": "13",
   "Type": "c",
   "WC": "2022-01-29 00:00:00"
 }
]},
  "layer": [
    {
      "mark": {"type": "line"},
      "encoding": {
        "y": {"field": "Weekly Avg"},
        "color": {
          "field": "Type",
          "scale": {
            "range": [
              "#4795CA",
              "#F9B96A",
              "#779E41",
              "#F54f0F",
              "#cfcfcf"
            ]
          }
        }
      }
    },
    {
      "mark": {"type": "line"},
      "encoding": {
        "y": {
          "field": "Weekly Avg",
          "aggregate": "sum"
        },
        "color": {"datum": "Total"}
      }
    },
    {
      "mark": {
        "type": "line",
        "strokeDash": [5, 5]
      },
      "transform": [
        {
          "regression": "Weekly Avg",
          "on": "WC",
          "groupBy": "WC"
        }
      ],
      "encoding": {
        "y": {
          "field": "Weekly Avg"
        },
        "color": {"datum": "Trend"}
      }
    }
  ],
  "encoding": {
    "x": {
      "field": "WC",
      "timeUnit": "monthdateyear",
      "type": "ordinal",
      "axis": {"format": "%d/%m/%Y"}
    },
    "y": {
      "type": "quantitative",
      "axis": {"format": "~s"}
    }
  }
}

Helpful resources

Announcements
June 2022 update 768X460.jpg

Check it out!

Click here to read more about the June 2022 updates!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.