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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Sergiy
Resolver II
Resolver II

Deneb: dynamically change the definition of a tooltip

Hi,

 

Here is my Deneb code:

 

 

{
  "data": {"name": "dataset"},
  "layer": [
    {
      "mark": {
        "type": "bar",
        "opacity": 0.3
      },
      "encoding": {
        "x": {"field": "b"},
        "tooltip": [
          {"field": "a"},
          {"field": "b"},
          {"field": "b__highlight", "title": "Highlighted"}
        ]
      }
    },
    {
      "mark": {
        "type": "bar",
        "tooltip": true
      },
      "encoding": {
        "x": {
          "field": "b__highlight"
        },
        "tooltip": [
          {"field": "a"},
          {"field": "b"},
          {"field": "b__highlight", "title": "Highlighted"}
        ],
        "opacity": {
          "condition": {
            "test": {
              "field": "__selected__",
              "equal": "off"
            },
            "value": 0
          },
          "value": 1
        }
      }
    }
  ],
  "encoding": {
    "y": {
      "field": "a",
      "type": "nominal"
    },
    "x": {
      "type": "quantitative",
      "axis": {"title": "b"}
    }
  }
}

 

 

There are two layers. Each layer has its own tooltip definition.

 

What I'd like is to have the ability to dynamically change the definition of the tooltip in the 2d layer.

For example, if "b_highlightStatus" = "on" then the definition should be as following:

 

"tooltip": [
  {"field": "a"},
  {"field": "b"},
  {"field": "b__highlight", "title": "Highlighted"}
]

 

 

... and if "b_highlightStatus" <> "on" then the definition should read as:

 

"tooltip": [
  {"field": "a"},
  {"field": "b"}
]

 

 

I tried to use exp & params but could not succeed.

I would be grateful for a short example of how to solve the issue.

Thanks

1 ACCEPTED SOLUTION

the code I was looking for looks like the following

 

{
  "data": {"name": "dataset"},
  "layer": [
    {
      "mark": {
        "type": "bar",
        "opacity": 0.3, 
        "tooltip": {
          "expr": "datum.b__highlight==null? {'a':datum['a'],'b':datum.b}:{'a':datum.a,'b':datum.b,'Highlighted':datum.b__highlight}"
        }
      },
      "encoding": {"x": {"field": "b"}}
    },
    {
      "mark": {
        "type": "bar",
        "tooltip": {
          "expr": "datum.b__highlightStatus=='on'? {'a':datum.a,'b':datum.b,'Highlighted':datum.b__highlight}:{'a':datum.a,'b':datum.b}"
        }
      },
      "encoding": {
        "x": {"field": "b__highlight"},
        "opacity": {
          "condition": {
            "test": {
              "field": "__selected__",
              "equal": "off"
            },
            "value": 0
          },
          "value": 1
        }
      }
    }
  ],
  "encoding": {
    "y": {
      "field": "a",
      "type": "nominal"
    },
    "x": {
      "type": "quantitative",
      "axis": {"title": "b"}
    }
  }
}

View solution in original post

3 REPLIES 3
TomMartens
Super User
Super User

Hey @Sergiy ,

 

please prepare a pbix that contains sample data, but still represents your data model (tables, relationships, calculated columns, and measures). Upload the pbix to OneDrive, Google Drive, or Dropbox, and share the link.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Hi @TomMartens .

 

I uploaded a sample file:

https://www.dropbox.com/scl/fi/l7qs306bklj0fc2lnr0tq/deneb_tooltip.pbix?rlkey=rx2pk9mopvwqhp7bq1fp08... 

 

The code is a bit different, but the idea is the same.

There are two layers. Each layer has its own tooltip definition.

What I'd like is to have the ability to dynamically change the definition of the tooltip in the 2d layer.

For example, if "b_highlightStatus" = "on" then the definition should be as following:

"tooltip": [
  {"field": "a"},
  {"field": "b"},
  {"field": "b__highlight", "title": "Highlighted"}
]

... and if "b_highlightStatus" <> "on" then the definition should read as:

"tooltip": [
  {"field": "a"},
  {"field": "b"}
]

 

the code I was looking for looks like the following

 

{
  "data": {"name": "dataset"},
  "layer": [
    {
      "mark": {
        "type": "bar",
        "opacity": 0.3, 
        "tooltip": {
          "expr": "datum.b__highlight==null? {'a':datum['a'],'b':datum.b}:{'a':datum.a,'b':datum.b,'Highlighted':datum.b__highlight}"
        }
      },
      "encoding": {"x": {"field": "b"}}
    },
    {
      "mark": {
        "type": "bar",
        "tooltip": {
          "expr": "datum.b__highlightStatus=='on'? {'a':datum.a,'b':datum.b,'Highlighted':datum.b__highlight}:{'a':datum.a,'b':datum.b}"
        }
      },
      "encoding": {
        "x": {"field": "b__highlight"},
        "opacity": {
          "condition": {
            "test": {
              "field": "__selected__",
              "equal": "off"
            },
            "value": 0
          },
          "value": 1
        }
      }
    }
  ],
  "encoding": {
    "y": {
      "field": "a",
      "type": "nominal"
    },
    "x": {
      "type": "quantitative",
      "axis": {"title": "b"}
    }
  }
}

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.