Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
kikko
Contributor II
Contributor II

How to use a field as label creating KPI on the fly?

Hi All,

I can't find a solution to the problem I'm facing. I used visualization API to create the KPI object on the fly in my mashup.

Now I want to use values contained in a specific field "Label_Europe" to let the labels of the object to change language based on the Market selected in mashup. While in sense application I can use this field to obtain the correct result, I can't get same result in mashup object. Please watch at my code below:

 

 

 

app.visualization.create( 
	'kpi',
	  [
		{
      "qDef": {
        "qLabel": "=Label_Europe",
        "qDef": "RankingEU.Ranking",
        "qNumFormat": {
		"qType": "F",
          "qnDec": 2,
          "qUseThou": 0,
          "qFmt": "0°",
          "qDec": ".",
          "qThou": ","
          
        },
		"conditionalColoring": {
          "useConditionalColoring": true,
          "segments": {
            "limits": [
              {
                "value": {
                  "qValueExpression": {
                    "qExpr": "RankingEU_Prev.Ranking-0.001"
                  }
                },
                "gradient": false
              },
			  {
                "value": {
                  "qValueExpression": {
                    "qExpr": "RankingEU_Prev.Ranking+0.001"
                  }
                },
                "gradient": false
              }
            ],
            "paletteColors": [
              {
                "color": "#04912b",
                "icon": "R",
                "index": -1
              },
			  {
                "color": "#fc9003",
                "icon": "T",
                "index": -1
              },
              {
                "color": "#db1f12",
                "icon": "S",
                "index": -1
              }
            ]
          }
        }
      }
    },
	{
      "qDef": {
        "qLabel": "PREV",
        "qDef": "RankingEU_Prev.Ranking",
        "qNumFormat": {
          "qType": "F",
          "qnDec": 2,
          "qUseThou": 0,
          "qFmt": "0°",
          "qDec": ".",
          "qThou": ","
        },
        "conditionalColoring": {
          "paletteSingleColor": {
            "index": -1,
            "color": "#5c5b5b"
          }
        }
      }
    }
	  ],
	  {
	  "showTitles": false,
	  "showMeasureTitle": true,
	  "textAlign": "center",
	  "fontSize": "L"
	}
	).then(function(vis){
	  vis.show("EU_rank");//Europe ranking
	});

 

 

 

As you can see I used the field "Label_Europe" to populate the "qlabel"  as "qLabel": "=Label_Europe" but we I open my mashup this is what I see:

KPI.jpg

 

I think that using double quote in the code to indicate the field is a wrong approch because the engine interprets as string what is included in double quote. There should be a way to let engine to read the "=Label_Europe" as an expression, but I don't know how!!

Can someone help me please?

thank you All for the support

Federico

1 Solution

Accepted Solutions
kikko
Contributor II
Contributor II
Author

Ok just solved my issue by my self! 😂

As you can see I was using the code below to define the label of my KPI object. 

"qLabel": "=Label_Europe",

But "qlabel" can be used only for static (not calculated) labels. After hours of  Sense manual surfing I have found the solution.

Instead of using "qlabel" you just want to use "qLabelExpression".

"qLabelExpression":"Label_Europe",

 

in this way the engine is able to interpret the argument "Label_Europe" as a field extracting the value from the field based on applied filters and then you can show a variable/dynamic Label.

So thank you to my myself!! I'm proud of me!! 🤣

View solution in original post

1 Reply
kikko
Contributor II
Contributor II
Author

Ok just solved my issue by my self! 😂

As you can see I was using the code below to define the label of my KPI object. 

"qLabel": "=Label_Europe",

But "qlabel" can be used only for static (not calculated) labels. After hours of  Sense manual surfing I have found the solution.

Instead of using "qlabel" you just want to use "qLabelExpression".

"qLabelExpression":"Label_Europe",

 

in this way the engine is able to interpret the argument "Label_Europe" as a field extracting the value from the field based on applied filters and then you can show a variable/dynamic Label.

So thank you to my myself!! I'm proud of me!! 🤣