cancel
Showing results for 
Search instead for 
Did you mean: 

Conditional Text in BloX Widget

BDenman24
8 - Cloud Apps
8 - Cloud Apps

Hello,

I'm still pretty new at BloX widgets, so hopefully this is a simple correction.  I am trying to make a BloX widget have conditional text if a value is below another value, display text, else display another text.  I am able to get the background color to change based upon that criteria, but not the text.  Below is my code:

{
"style": "",
"script": "",
"title": "",
"showCarousel": true,
"carouselAnimation": {
"delay": 0
},
"conditions": [
{
"minRange": "-Infinity",
"maxRange": "{panel:DIR Company Avg}",
"backgroundColor": "#fd6e69"
},
{
"minRange": "{panel:DIR Company Avg}",
"maxRange": "Infinity",
"backgroundColor": "#3adcca"
}
],
"body": [
{
"spacing": "none",
"type": "Container",
"items": [
{
"spacing": "small",
"type": "TextBlock",
"class": "condition_data",
"text": "Your DIR score is {panel: DIR Score}",
"horizontalAlignment": "center",
"size": "large",
"weight": "bold",
"color": "white"
}
]
}
],
"conditionsTarget": [
{
"data-class": "condition_data",
"conditions": [
{
"minRange": "-Infinity",
"maxRange": "{panel:DIR Company Avg}",
"type": "TextBlock",
"text": "below avg"
},
{
"minRange": "{panel:DIR Company Avg}",
"maxRange": "Infinity",
"type": "TextBlock",
"text": "above avg"
}
]
}
]
}
Any help would be greatly appreciated!  Thanks!
1 ACCEPTED SOLUTION

harikm007
13 - Data Warehouse
13 - Data Warehouse

Hi @BDenman24 ,

One solution is as follows:

  1. Create a measure titled 'Is Above' that returns 1 if the value is "Above Avg" and 0 if it is "Below Avg." Your formula may look something like this: 

 

case when sum([DIR Score]) > AVG([DIR Company Avg]) then 1 else 0 end

harikm007_4-1725962547948.png

 

 

  • Update the BloX script with the following:

 

{
    "style": "",
    "script": "",
    "title": "",
    "showCarousel": true,
    "carouselAnimation": {
        "delay": 0
    },
    "conditions": [
        {
            "minRange": "-Infinity",
            "maxRange": "{panel:DIR Company Avg}",
            "backgroundColor": "#fd6e69"
        },
        {
            "minRange": "{panel:DIR Company Avg}",
            "maxRange": "Infinity",
            "backgroundColor": "#3adcca"
        }
    ],
    "body": [
        {
            "spacing": "none",
            "type": "Container",
            "items": [
                {
                    "spacing": "small",
                    "type": "TextBlock",
                    "class": "condition_data",
                    "text": "Your DIR score is {panel: DIR Score}",
                    "horizontalAlignment": "center",
                    "size": "small",
                    "weight": "bold",
                    "color": "white"
                },
                {
                    "spacing": "small",
                    "type": "TextBlock",
                    "text": "{panel: Is Above}",
                    "horizontalAlignment": "center",
                    "size": "small",
                    "weight": "bold",
                    "color": "white"
                }
            ]
        }
    ]
}​

 

  • Add the widget script to the BloX widget:

 

widget.on('processresult', function(w, args){
		
	args.result.forEach(item => {
		
		Object.keys(item).forEach(el => {
			if(item[el].Panel === 'Is Above') {
				if(item[el].Value === 0)
					item[el].Text = 'Below Avg'
				else
					item[el].Text = 'Above Avg'
			}
		
		})
	})

})​

 

Here's the result: 

chrome-capture-2024-9-10 (1).gif

Please let me know if this works for you.

 

Thanks,

Hari

https://www.binextlevel.com/ 

View solution in original post

4 REPLIES 4

Thanks for the response!  I tried a lot of the solutions you pointed out and nothing really solved my issue.  However, Hari's solution below did!  Thanks again!

harikm007
13 - Data Warehouse
13 - Data Warehouse

Hi @BDenman24 ,

One solution is as follows:

  1. Create a measure titled 'Is Above' that returns 1 if the value is "Above Avg" and 0 if it is "Below Avg." Your formula may look something like this: 

 

case when sum([DIR Score]) > AVG([DIR Company Avg]) then 1 else 0 end

harikm007_4-1725962547948.png

 

 

  • Update the BloX script with the following:

 

{
    "style": "",
    "script": "",
    "title": "",
    "showCarousel": true,
    "carouselAnimation": {
        "delay": 0
    },
    "conditions": [
        {
            "minRange": "-Infinity",
            "maxRange": "{panel:DIR Company Avg}",
            "backgroundColor": "#fd6e69"
        },
        {
            "minRange": "{panel:DIR Company Avg}",
            "maxRange": "Infinity",
            "backgroundColor": "#3adcca"
        }
    ],
    "body": [
        {
            "spacing": "none",
            "type": "Container",
            "items": [
                {
                    "spacing": "small",
                    "type": "TextBlock",
                    "class": "condition_data",
                    "text": "Your DIR score is {panel: DIR Score}",
                    "horizontalAlignment": "center",
                    "size": "small",
                    "weight": "bold",
                    "color": "white"
                },
                {
                    "spacing": "small",
                    "type": "TextBlock",
                    "text": "{panel: Is Above}",
                    "horizontalAlignment": "center",
                    "size": "small",
                    "weight": "bold",
                    "color": "white"
                }
            ]
        }
    ]
}​

 

  • Add the widget script to the BloX widget:

 

widget.on('processresult', function(w, args){
		
	args.result.forEach(item => {
		
		Object.keys(item).forEach(el => {
			if(item[el].Panel === 'Is Above') {
				if(item[el].Value === 0)
					item[el].Text = 'Below Avg'
				else
					item[el].Text = 'Above Avg'
			}
		
		})
	})

})​

 

Here's the result: 

chrome-capture-2024-9-10 (1).gif

Please let me know if this works for you.

 

Thanks,

Hari

https://www.binextlevel.com/ 

This works great!  Thank yo so much Hari!