Forum Discussion

BDenman24's avatar
BDenman24
Cloud Apps
09-05-2024
Solved

Conditional Text in BloX Widget

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 ...
  • harikm007's avatar
    09-10-2024

    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

     

     

    • 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: 

    Please let me know if this works for you.

     

    Thanks,

    Hari

    https://www.binextlevel.com/