Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Fern_21
Advocate III
Advocate III

How to add multiple trend lines in Deneb and make them dynamic based on filters

Hi all!

I've this Power BI Deneb code to create a scatter chart. It shows open projects (red) and closed projects (blue), plus two trend lines: a black one for all closed projects, and a blue one for the filtered closed projects. The filter distinguishing open and closed uses this column:

ProjectType =
SWITCH(
TRUE(),
facilities[project_phase] = "DETAIL", "Opened",
facilities[project_phase] = "FEED", "Closed",
BLANK()
)

I need to display both lines — the blue and the black — even when I select a subset of closed projects through filtering.

How can I make sure that the black line (representing all closed projects) remains visible when I apply filters on closed projects?

Please note that all the measures I use on the X and Y axes come from different tables.
This is the code I currently use for deneb:
{ "$schema": "https://vega.github.io/schema/vega-lite/v5.json", "width": 600, "height": 400, "padding": 5, "data": { "name": "dataset" }, "params": [ { "name": "xParam", "value": "Area_Module_2", "bind": { "input": "select", "options": [ "Area_Module_2", "Volume_Module", "GrossWeightMeasure_ModuleReport", "OperativeWeightMeasure_FacilityReport", "Eq Gross DryT", "Eq Gross Operating (t)" ], "labels": [ "Total Area (m²)", "Total Volume (m³)", "Gross Dry Weight (t)", "Gross Operating Weight (t)", "Eq Gross Dry Weight (t)", "Eq Gross Operating Weight (t)" ], "name": "X Axis" } }, { "name": "yParam", "value": "TotalGrossDryWeight", "bind": { "input": "select", "options": [ "TotalGrossDryWeight", "TotalGrossOperativeWeight" ], "labels": [ "Gross Dry Weight (t)", "Gross Operative Weight (t)" ], "name": "Y Axis" } } ], "layer": [ { "transform": [ { "filter": "isValid(datum[xParam]) && isValid(datum[yParam])" }, { "calculate": "datum[xParam]", "as": "xField" }, { "calculate": "datum[yParam]", "as": "yField" }, { "calculate": "xParam + ' = ' + datum[xParam]", "as": "X" }, { "calculate": "yParam + ' = ' + datum[yParam]", "as": "Y" } ], "mark": "point", "encoding": { "x": { "field": "xField", "type": "quantitative", "title": { "expr": "switch(xParam, 'Area_Module_2', 'Total Area (m²)', 'Volume_Module', 'Total Volume (m³)', 'GrossWeightMeasure_ModuleReport', 'Gross Dry Weight (t)', 'OperativeWeightMeasure_FacilityReport', 'Gross Operating Weight (t)', 'Eq Gross DryT', 'Eq Gross Dry Weight (t)', 'Eq Gross Operating (t)', 'Eq Gross Operating Weight (t)', 'Unknown')" } }, "y": { "field": "yField", "type": "quantitative", "title": { "expr": "switch(yParam, 'TotalGrossDryWeight', 'Gross Dry Weight (t)', 'TotalGrossOperativeWeight', 'Gross Operative Weight (t)', 'Unknown')" } }, "color": { "field": "ProjectType", "type": "nominal", "scale": { "domain": ["Closed", "Opened"], "range": ["#1f77b4", "#d62728"] } }, "shape": { "field": "ProjectType", "type": "nominal", "scale": { "domain": ["Closed", "Opened"], "range": ["circle", "triangle"] } }, "tooltip": [ { "field": "X", "type": "nominal", "title": null }, { "field": "Y", "type": "nominal", "title": null }, { "field": "RevisionNum", "type": "nominal", "title": "Revision" }, { "field": "facility_code", "type": "nominal", "title": "Facility Code" }, { "field": "ProjectType", "type": "nominal", "title": "Project Type" } ], "opacity": { "condition": { "test": "datum.ProjectType === 'Closed'", "value": 0.6 }, "value": 1 } } }, { "transform": [ { "filter": "datum.ProjectType === 'Closed' && isValid(datum['Area_Module_2']) && isValid(datum['TotalGrossDryWeight'])" }, { "calculate": "datum['Area_Module_2']", "as": "xField" }, { "calculate": "datum['TotalGrossDryWeight']", "as": "yField" }, { "regression": "yField", "on": "xField", "method": "linear" } ], "mark": { "type": "line", "color": "black", "strokeDash": [4, 4], "strokeWidth": 2 }, "encoding": { "x": { "field": "xField", "type": "quantitative" }, "y": { "field": "yField", "type": "quantitative" } } }, { "transform": [ { "filter": "datum.ProjectType === 'Closed' && isValid(datum[xParam]) && isValid(datum[yParam])" }, { "calculate": "datum[xParam]", "as": "xField" }, { "calculate": "datum[yParam]", "as": "yField" }, { "regression": "yField", "on": "xField", "method": "linear" } ], "mark": { "type": "line", "color": "#1f77b4", "strokeDash": [4, 4], "strokeWidth": 2 }, "encoding": { "x": { "field": "xField", "type": "quantitative" }, "y": { "field": "yField", "type": "quantitative" } } } ] }

Thanks

Fern_21_0-1756313729922.png

Fern_21_1-1756313758678.png

 



1 ACCEPTED SOLUTION

Hi @Fern_21,

Thank you for reaching out to the Microsoft fabric community forum. I reproduced the scenario again, and it worked on my end.

By default, slicers in Power BI affect all visuals on a page. To achieve the expected behavior where visuals are not impacted by slicers, we created a duplicate page and used bookmarks as a workaround.

I am also including .pbix file for your better understanding, please have a look into it:

Hope this helps clarify things and let me know what you find after giving these steps a try happy to help you investigate this further.

Thank you for using the Microsoft Fabric Community Forum.

View solution in original post

12 REPLIES 12
v-kpoloju-msft
Community Support
Community Support

Hi @Fern_21

Thank you for reaching out to the Microsoft fabric community forum. Also, thanks to @Shahid12523, for his inputs on this thread. I reproduced the scenario, and it worked on my end. I used my sample data and successfully implemented it.


I am also including .pbix file for your better understanding, please have a look into it:

Hope this helps clarify things and let me know what you find after giving these steps a try happy to help you investigate this further.

Thank you for using the Microsoft Fabric Community Forum.

Hi @v-kpoloju-msft !

Thank you for your help. I'm in the same situation. What I would like to further implement is a black line that represents all closed projects, regardless of which closed project is currently filtered. Also, when a closed project is selected, the black line and the open projects should not disappear.

{
  "width": 600,
  "height": 400,
  "padding": 5,
  "data": { "name": "dataset" },
  "params": [
    {
      "name": "xParam",
      "value": "Area_Module_2",
      "bind": {
        "input": "select",
        "options": [
          "Area_Module_2",
          "Volume_Module",
          "GrossWeightMeasure_ModuleReport",
          "OperativeWeightMeasure_FacilityReport",
          "Eq Gross DryT",
          "Eq Gross Operating (t)"
        ],
        "labels": [
          "Total Area (m²)",
          "Total Volume (m³)",
          "Gross Dry Weight (t)",
          "Gross Operating Weight (t)",
          "Eq Gross Dry Weight (t)",
          "Eq Gross Operating Weight (t)"
        ],
        "name": "X Axis"
      }
    },
    {
      "name": "yParam",
      "value": "TotalGrossDryWeight",
      "bind": {
        "input": "select",
        "options": [
          "TotalGrossDryWeight",
          "TotalGrossOperativeWeight"
        ],
        "labels": [
          "Gross Dry Weight (t)",
          "Gross Operative Weight (t)"
        ],
        "name": "Y Axis"
      }
    }
  ],
  "layer": [
    // 🔘 Scatterplot: punti blu e rossi sempre visibili, filtro interno per differenziare
    {
      "transform": [
        {
          "filter": "isValid(datum[xParam]) && isValid(datum[yParam]) && (datum.ProjectType === 'Closed' || datum.ProjectType === 'Opened')"
        },
        { "calculate": "datum[xParam]", "as": "xField" },
        { "calculate": "datum[yParam]", "as": "yField" },
        { "calculate": "xParam + ' = ' + datum[xParam]", "as": "X" },
        { "calculate": "yParam + ' = ' + datum[yParam]", "as": "Y" }
      ],
      "mark": "point",
      "encoding": {
        "x": {
          "field": "xField",
          "type": "quantitative",
          "title": {
            "expr": "switch(xParam, 'Area_Module_2', 'Total Area (m²)', 'Volume_Module', 'Total Volume (m³)', 'GrossWeightMeasure_ModuleReport', 'Gross Dry Weight (t)', 'OperativeWeightMeasure_FacilityReport', 'Gross Operating Weight (t)', 'Eq Gross DryT', 'Eq Gross Dry Weight (t)', 'Eq Gross Operating (t)', 'Eq Gross Operating Weight (t)', 'Unknown')"
          }
        },
        "y": {
          "field": "yField",
          "type": "quantitative",
          "title": {
            "expr": "switch(yParam, 'TotalGrossDryWeight', 'Gross Dry Weight (t)', 'TotalGrossOperativeWeight', 'Gross Operative Weight (t)', 'Unknown')"
          }
        },
        "color": {
          "field": "ProjectType",
          "type": "nominal",
          "scale": {
            "domain": ["Closed", "Opened"],
            "range": ["#1f77b4", "#d62728"]
          }
        },
        "shape": {
          "field": "ProjectType",
          "type": "nominal",
          "scale": {
            "domain": ["Closed", "Opened"],
            "range": ["circle", "triangle"]
          }
        },
        "tooltip": [
          { "field": "X", "type": "nominal", "title": null },
          { "field": "Y", "type": "nominal", "title": null },
          { "field": "RevisionNum", "type": "nominal", "title": "Revision" },
          { "field": "facility_code", "type": "nominal", "title": "Facility Code" },
          { "field": "ProjectType", "type": "nominal", "title": "Project Type" }
        ],
        "opacity": {
          "condition": {
            "test": "datum.ProjectType === 'Closed'",
            "value": 0.6
          },
          "value": 1
        }
      }
    },
 
    // Linea nera: regressione su tutti i progetti chiusi (ProjectType_RAW = 'FEED'), indipendente da filtri Power BI
    {
      "transform": [
        {
          "filter": "datum.ProjectType_RAW === 'FEED' && isValid(datum[xParam]) && isValid(datum[yParam])"
        },
        { "calculate": "datum[xParam]", "as": "xField" },
        { "calculate": "datum[yParam]", "as": "yField" },
        {
          "regression": "yField",
          "on": "xField",
          "method": "linear"
        }
      ],
      "mark": {
        "type": "line",
        "color": "black",
        "strokeDash": [4, 4],
        "strokeWidth": 2
      },
      "encoding": {
        "x": { "field": "xField", "type": "quantitative" },
        "y": { "field": "yField", "type": "quantitative" }
      }
    },
 
    // 🔵 Linea blu: regressione solo sui dati filtrati (ProjectType = 'Closed')
    {
      "transform": [
        {
          "filter": "datum.ProjectType === 'Closed' && isValid(datum[xParam]) && isValid(datum[yParam])"
        },
        { "calculate": "datum[xParam]", "as": "xField" },
        { "calculate": "datum[yParam]", "as": "yField" },
        {
          "regression": "yField",
          "on": "xField",
          "method": "linear"
        }
      ],
      "mark": {
        "type": "line",
        "color": "#1f77b4",
        "strokeDash": [4, 4],
        "strokeWidth": 2
      },
      "encoding": {
        "x": { "field": "xField", "type": "quantitative" },
        "y": { "field": "yField", "type": "quantitative" }
      }
    }
  ]
}
This is the code I'm using. @Shahid12523said to create a second unfiltered dataset but I can't

 

Hi @Fern_21,

Thank you for reaching out to the Microsoft fabric community forum. I reproduced the scenario again, and it worked on my end.

By default, slicers in Power BI affect all visuals on a page. To achieve the expected behavior where visuals are not impacted by slicers, we created a duplicate page and used bookmarks as a workaround.

I am also including .pbix file for your better understanding, please have a look into it:

Hope this helps clarify things and let me know what you find after giving these steps a try happy to help you investigate this further.

Thank you for using the Microsoft Fabric Community Forum.

Hi!
Thank you for your solution. Is it absolutely necessary to use two pages for it to function properly?

Furthermore, the second chart should display the selected project in a highlighted state. To clarify: when project_id F1 is selected on the filtered page, the unfiltered page should still show the current chart (which is correct), but with F1 visually emphasized to indicate the selection.

Thanks


Hi @Fern_21,
Thank you for the follow-up question.

Yes as part of workaround this is the only way to show the constant black line in the chart using bookmarks. 

Thank you for using the Microsoft Fabric Community Forum.

Hi @Fern_21,

Hope you had a chance to try out the solution shared earlier. Let us know if anything needs further clarification or if there's an update from your side always here to help.

Thank you.

Hi @Fern_21,

Just checking in to see if the issue has been resolved on your end. If the earlier suggestions helped, that’s great to hear! And if you’re still facing challenges, feel free to share more details happy to assist further.

Thank you.

Hi @Fern_21,

Just checking in to see if the issue has been resolved on your end. If the earlier suggestions helped, that’s great to hear! And if you’re still facing challenges, feel free to share more details happy to assist further.

Thank you.

@Fern_21 Hey,

you need to adjust the data transformations used for creating the trend lines. Here's a brief explanation of how you can achieve this:

Steps:

  1. Data Preparation: Ensure that the dataset includes all closed projects, irrespective of filters. This can be done by creating a calculated table or measure that always selects all closed projects even when a subset is filtered in your visual.
  1. Deneb Code Adjustment:


- Black Line (All Closed Projects):
- Use a transformation step outside the filtering scope to ensure it always includes all closed projects. This step should not be affected by visual-level filters.
- Store the required data for all closed projects in a separate data preparation step, separate from the filtered data.

Blue Line (Filtered Closed Projects):
- This trend line can use the current filtered data – i.e., the subset you're selecting.

 

Adjust the transformation layers in your Deneb code as follows:

{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
...
"layer": [
// Existing Project Points Layer
{
"transform": [
// Use filter only for visualization
],
"mark": "point",
...
},
// Black Line Layer (All Closed Projects)
{
"transform": [
{
"filter": "datum.ProjectType === 'Closed' && isValid(datum['Area_Module_2']) && isValid(datum['TotalGrossDryWeight'])"
},
{
"regression": "TotalGrossDryWeight",
"on": "Area_Module_2",
"method": "linear",
"groupby": ["CompleteProjectType"] // Ensure data scope is for all closed projects
}
],
...
},
// Blue Line Layer (Filtered Closed Projects)
{
"transform": [
{
"filter": "datum.ProjectType === 'Closed' && isValid(datum[xParam]) && isValid(datum[yParam])"
},
{
"regression": "yField",
"on": "xField",
"method": "linear"
}
],
...
}
]
}
 
  • Maintain a static data source for the black line representing all closed projects. This avoids disruption due to interactive filters affecting visual subsets.
  • Separate transformation processes to distinguish between the complete dataset required for the black line and the dynamically filtered data for the blue line.

Thanks

Harish M

Shahid12523
Community Champion
Community Champion

Create a separate unfiltered table in Power BI (e.g., AllClosedProjects)
Add it as a second dataset in Deneb
Use that dataset for the black trend line layer
This way, filters affect only the blue line, while the black line always shows all closed projects. Clean, dynamic, and filter-proof.

Shahed Shaikh

Hi @Shahid12523 !

How can you insert a second dataset into Deneb?
Thanks

Hi @Shahid12523 !

How do I create AllClosedProjects? The dataset I need contains measurements to use on the x-axis and y-axis and they are part of different tables, connected to each other via the facts table. For example, I have Area and Volume present in modules and total gross weight present in items. The project type to define open or closed projects is present in facilities. Could you give me an example?

Thanks

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors