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
ThomasSan
Helper IV
Helper IV

Conditional formatting in Deneb

Hi everyone,

 

I am attempting to create a custom made KPI card visual via Deneb (the PBI card visual simply do not give enough benchmark values to compare the main KPI, I find).

 

To do that, I would like to have the KPI displayed as concise as possible. Therefore, I would like to have the visual adapt the formatting of the KPI value to a k (for thousand) or m (for million) suffix i.e. €219,677 displayed as €219k and €1,488,010 as €1.5m.

 

However, I seem to have difficulties setting up my condition section accordingly. I am currently having the following Deneb code

 

 

 

{
  "data": {"name": "dataset"},
  "layer": [
    {
      "mark": {
        "type": "text",
        "fontSize": 25,
        "fontWeight": 600,
        "dx": 0,
        "dy": -35,
        "color": "#454545",
        "align": "center"
      },
      "encoding": {
        "text": {
          "field": "Text YTD Sales"
        }
      }
    },
    {
      "mark": {
        "type": "text",
        "fontWeight": 400,
        "size": 30,
        "color": "#454545",
        "align": "center"
      },
      "encoding": {
        "text": {
          "field": "YTD of CY",
          "aggregate": "sum",
          "type": "quantitative",
          "format": {
            "condition": {
              "test": "datum['YTD of CY'] < 100000",
              "value": "#, €",
              "test": "datum['YTD of CY'] >= 100000",
              "value": "#,.k €"
            },
            "value": "#,,.0m €"
          },
          "formatType": "pbiFormat"
        }
      }
    }
  ]
}

 

 

 

As you can see, I tried to copy how they did it in the documentation here https://vega.github.io/vega-lite/docs/condition.html#condition 

(section "condition": {"test": "datum['num_cars'] < 40", "value": "black"} )

 

I also tried this alternative code based on the documentation here https://vega.github.io/vega-lite/docs/predicate.html

 

 

 

{
  "data": {"name": "dataset"},
  "layer": [
    {
      "mark": {
        "type": "text",
        "fontSize": 25,
        "fontWeight": 600,
        "dx": 0,
        "dy": -35,
        "color": "#454545",
        "align": "center"
      },
      "encoding": {
        "text": {
          "field": "Text YTD Sales"
        }
      }
    },
    {
      "mark": {
        "type": "text",
        "fontWeight": 400,
        "size": 30,
        "color": "#454545",
        "align": "center"
      },
      "encoding": {
        "text": {
          "field": "YTD of CY",
          "aggregate": "sum",
          "type": "quantitative",
          "format": {
            "condition": {
              "test": {
                "field": "YTD of CY",
                "lt": 100000
              },
              "value": "#, €",
			  "test": {
                "field": "YTD of CY",
                "gte": 100000
              },
              "value": "#,.k €"
            },
            "value": "#,,.0m €"
          },
          "formatType": "pbiFormat"
        }
      }
    }
  ]
}

 

 

 

Unfortunately, this also did not yield any results:

ThomasSan_0-1718201948570.png

 

I do get the correct figure displayed when I leave the conditional formatting away altogether but then I am trying for a Deneb visual as it would give me more freedom to design a KPI card visual on my personal requirements. 

 

Can anyone please help enlighten me here? I really do not understand why neither of my attempts to build in conditional formatting actually works. Thanks!

 

1 REPLY 1
lbendlin
Super User
Super User

Not sure if that helps in your scenario but Deneb also supports Power BI formatting

Exploring the Power of the pbiFormat() Function in Deneb | CSalcedoDataBI

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! Prices go up Feb. 11th.

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.