🃏
Explorador de KPIs por Categoría
Plantilla interactiva que te permite visualizar y comparar tendencias de tus indicadores clave de rendimiento según cualquier categoría. Selecciona dinámicamente la métrica y la categoría para ver la evolución mensual, detectar patrones y tomar decisiones basadas en datos de manera ágil y clara. autor: Cristobal Salcedo Beltran
Vega-Lite card avanzado
✓ Tooltip
Vista previa en vivo
Visual real en Power BI
Vista previa renderizada con el runtime de Deneb · MIT © Daniel Marsh-Patrick
🎯 Técnica
- Motor
- Vega-Lite 5.16.3
- Marks
- line, rect, text
- Power BI
- pbiFormat, pbiFormatAutoUnit
Cómo usarlo en Power BI
- Agrega el visual Deneb a tu reporte e ingresa a su editor.
-
Arrastra tus campos a Values siguiendo el orden del dataset (
__0__,__1__…). - Pega el spec (botón «Copiar spec» arriba) en el editor JSON de Deneb.
- Mapea tus columnas y ajusta a tu gusto. La interactividad nativa ya viene configurada.
Ver el spec Vega-Lite completo
spec.vega-lite.json
{
"description": "Explorador de KPIs por Categoría,Plantilla interactiva que te permite visualizar y comparar tendencias de tus indicadores clave de rendimiento según cualquier categoría. Selecciona dinámicamente la métrica y la categoría para ver la evolución mensual, detectar patrones y tomar decisiones basadas en datos de manera ágil y clara. autor: Cristobal Salcedo Beltran",
"data": {
"name": "dataset"
},
"params": [
{
"name": "NombreDeMetrica",
"expr": "pluck(data(''dataset''),''MetricName'')[0]"
},
{
"name": "formatString",
"expr": "pluck(data(''dataset''),''MetricKPIValue__format'')[0]"
}
],
"transform": [
{
"window": [
{
"field": "MetricKPIValue",
"op": "first_value",
"as": "first_value"
},
{
"field": "End Of Month",
"op": "first_value",
"as": "first_date"
}
],
"groupby": [
"Category"
]
},
{
"window": [
{
"field": "MetricKPIValue",
"op": "last_value",
"as": "last_value"
},
{
"field": "End Of Month",
"op": "last_value",
"as": "last_date"
},
{
"field": "End Of Month",
"op": "count",
"as": "CountRow"
},
{
"field": "MetricKPIValue",
"op": "average",
"as": "PromedioDeVentas"
},
{
"field": "MetricKPIValue",
"op": "sum",
"as": "totalDeVentas"
}
],
"frame": [
null,
null
],
"groupby": [
"Category"
]
},
{
"calculate": "datum.last_value - datum.first_value",
"as": "SentimentColor"
},
{
"calculate": "(datum.last_value - datum.first_value) / datum.first_value",
"as": "PctDiff"
},
{
"calculate": "pbiFormat(datum.first_date,''MM-dd-yyyy'') + '' to ''+ pbiFormat(datum.last_date,''MM-dd-yyyy'')",
"as": "__date__"
},
{
"calculate": "datum[''Category''] + '': Promedio: '' + pbiFormat(datum.PromedioDeVentas,formatString,{value: datum.PromedioDeVentas >= 1e12 ? 1e12: datum.PromedioDeVentas >= 1e9? 1e9 : datum.PromedioDeVentas >= 1e6 ? 1e6: datum.PromedioDeVentas >= 1e3? 1e3: 1, precision:0 })",
"as": "__title__"
},
{
"window": [
{
"field": "Category",
"op": "dense_rank",
"as": "CategoryRank"
}
],
"sort": [
{
"field": "totalDeVentas",
"order": "descending"
}
],
"frame": [
null,
null
]
},
{
"window": [
{
"field": "Category",
"op": "dense_rank",
"as": "filasPorCategoria"
}
],
"groupby": [
"Category"
]
}
],
"spacing": 10,
"columns": 3,
"concat": [
{
"transform": [
{
"filter": "datum.CategoryRank == 1"
}
],
"width": 180,
"height": 120,
"layer": [
{
"transform": [
{
"filter": "datum.filasPorCategoria== 1"
}
],
"layer": [
{
"mark": {
"type": "rect",
"align": "left",
"fill": "gray",
"opacity": 0.1,
"height": 170,
"width": 365,
"yOffset": 60,
"xOffset": -180,
"cornerRadiusTopLeft": 15,
"cornerRadiusBottomLeft": 15
}
},
{
"mark": {
"type": "rect",
"align": "left",
"color": {
"expr": "NombreDeMetrica==''Total Cost''? datum.SentimentColor>0? ''firebrick'':''green'': datum.SentimentColor<0? ''firebrick'':''green''"
},
"height": 170,
"width": 15,
"yOffset": 60,
"xOffset": 180,
"cornerRadiusTopRight": 15,
"cornerRadiusBottomRight": 15
}
},
{
"mark": {
"type": "text",
"color": "black",
"fontWeight": 700,
"fontSize": 15
},
"encoding": {
"text": {
"value": {
"expr": "NombreDeMetrica"
}
},
"x": {
"value": -100
},
"y": {
"value": 40
}
}
},
{
"mark": {
"type": "text",
"align": "left",
"color": "black",
"fontWeight": 600,
"fontSize": 14
},
"encoding": {
"text": {
"field": "__title__"
},
"x": {
"value": -160
},
"y": {
"value": -52
}
}
},
{
"mark": {
"type": "text",
"color": "black",
"align": "left",
"fontWeight": 400,
"fontSize": 10
},
"encoding": {
"text": {
"field": "__date__"
},
"x": {
"value": -160
},
"y": {
"value": -35
}
}
},
{
"mark": {
"type": "text",
"color": {
"expr": "NombreDeMetrica==''Total Cost''? datum.SentimentColor>0? ''firebrick'':''green'': datum.SentimentColor<0? ''firebrick'':''green''"
},
"fontWeight": 700,
"fontSize": 25
},
"encoding": {
"text": {
"value": {
"expr": "pbiFormat(datum.totalDeVentas,formatString,{value: datum.totalDeVentas>=1e12? 1e12: datum.totalDeVentas>=1e9? 1e9: datum.totalDeVentas>= 1e6? 1e6: datum.totalDeVentas>=1e3? 1e3: 1,precision:0 })"
}
},
"x": {
"value": -100
},
"y": {
"value": 70
}
}
}
]
},
{
"mark": {
"type": "line",
"strokeWidth": 1.5,
"color": "black",
"opacity": 0.7,
"tooltip": true,
"point": {
"stroke": "white",
"strokeWidth": 0.5,
"size": 20,
"fill": "black"
}
},
"encoding": {
"y": {
"field": "MetricKPIValue"
}
}
},
{
"transform": [
{
"regression": "MetricKPIValue",
"on": "End Of Month"
},
{
"window": [
{
"field": "MetricKPIValue",
"op": "first_value",
"as": "first_value"
}
]
},
{
"window": [
{
"field": "MetricKPIValue",
"op": "last_value",
"as": "last_value"
}
],
"frame": [
null,
null
]
},
{
"calculate": "datum.last_value-datum.first_value",
"as": "SentimentColor"
}
],
"mark": {
"type": "line",
"strokeWidth": 1.5,
"strokeDash": [
4,
8
],
"color": {
"expr": "NombreDeMetrica==''Total Cost''? datum.SentimentColor>0? ''firebrick'':''green'': datum.SentimentColor<0? ''firebrick'':''green''"
}
},
"encoding": {
"x": {
"field": "End Of Month",
"type": "ordinal"
},
"y": {
"field": "MetricKPIValue",
"type": "quantitative"
}
}
}
],
"encoding": {
"x": {
"field": "End Of Month",
"timeUnit": "monthdate",
"type": "nominal",
"axis": {
"labelExpr": "pbiFormat(datum.value,''MM'')",
"title": "",
"labelFontSize": 8,
"labelSeparation": 1,
"tickCount": 10,
"domainColor": {
"expr": "indata(''data_0'',''CategoryRank'',1) ? ''gray'': ''transparent'' "
}
}
},
"y": {
"type": "quantitative",
"axis": {
"labelFontSize": 8,
"title": "",
"domainColor": {
"expr": "indata(''data_0'',''CategoryRank'',1) ? ''gray'': ''transparent'' "
}
},
"scale": {
"type": "linear",
"zero": false
}
}
}
},
{
"transform": [
{
"filter": "datum.CategoryRank == 2"
}
],
"width": 180,
"height": 120,
"layer": [
{
"transform": [
{
"filter": "datum.filasPorCategoria== 1"
}
],
"layer": [
{
"mark": {
"type": "rect",
"align": "left",
"fill": "gray",
"opacity": 0.1,
"height": 170,
"width": 365,
"yOffset": 60,
"xOffset": -180,
"cornerRadiusTopLeft": 15,
"cornerRadiusBottomLeft": 15
}
},
{
"mark": {
"type": "rect",
"align": "left",
"color": {
"expr": "NombreDeMetrica==''Total Cost''? datum.SentimentColor>0? ''firebrick'':''green'': datum.SentimentColor<0? ''firebrick'':''green''"
},
"height": 170,
"width": 15,
"yOffset": 60,
"xOffset": 180,
"cornerRadiusTopRight": 15,
"cornerRadiusBottomRight": 15
}
},
{
"mark": {
"type": "text",
"color": "black",
"fontWeight": 700,
"fontSize": 15
},
"encoding": {
"text": {
"value": {
"expr": "NombreDeMetrica"
}
},
"x": {
"value": -100
},
"y": {
"value": 40
}
}
},
{
"mark": {
"type": "text",
"align": "left",
"color": "black",
"fontWeight": 600,
"fontSize": 14
},
"encoding": {
"text": {
"field": "__title__"
},
"x": {
"value": -160
},
"y": {
"value": -52
}
}
},
{
"mark": {
"type": "text",
"color": "black",
"align": "left",
"fontWeight": 400,
"fontSize": 10
},
"encoding": {
"text": {
"field": "__date__"
},
"x": {
"value": -160
},
"y": {
"value": -35
}
}
},
{
"mark": {
"type": "text",
"color": {
"expr": "NombreDeMetrica==''Total Cost''? datum.SentimentColor>0? ''firebrick'':''green'': datum.SentimentColor<0? ''firebrick'':''green''"
},
"fontWeight": 700,
"fontSize": 25
},
"encoding": {
"text": {
"value": {
"expr": "pbiFormat(datum.totalDeVentas,formatString,{value: datum.totalDeVentas>=1e12? 1e12: datum.totalDeVentas>=1e9? 1e9: datum.totalDeVentas>= 1e6? 1e6: datum.totalDeVentas>=1e3? 1e3: 1,precision:0 })"
}
},
"x": {
"value": -100
},
"y": {
"value": 70
}
}
}
]
},
{
"mark": {
"type": "line",
"strokeWidth": 1.5,
"color": "black",
"opacity": 0.7,
"tooltip": true,
"point": {
"stroke": "white",
"strokeWidth": 0.5,
"size": 20,
"fill": "black"
}
},
"encoding": {
"y": {
"field": "MetricKPIValue"
}
}
},
{
"transform": [
{
"regression": "MetricKPIValue",
"on": "End Of Month"
},
{
"window": [
{
"field": "MetricKPIValue",
"op": "first_value",
"as": "first_value"
}
]
},
{
"window": [
{
"field": "MetricKPIValue",
"op": "last_value",
"as": "last_value"
}
],
"frame": [
null,
null
]
},
{
"calculate": "datum.last_value-datum.first_value",
"as": "SentimentColor"
}
],
"mark": {
"type": "line",
"strokeWidth": 1.5,
"strokeDash": [
4,
8
],
"color": {
"expr": "NombreDeMetrica==''Total Cost''? datum.SentimentColor>0? ''firebrick'':''green'': datum.SentimentColor<0? ''firebrick'':''green''"
}
},
"encoding": {
"x": {
"field": "End Of Month",
"type": "ordinal"
},
"y": {
"field": "MetricKPIValue",
"type": "quantitative"
}
}
}
],
"encoding": {
"x": {
"field": "End Of Month",
"timeUnit": "monthdate",
"type": "nominal",
"axis": {
"labelExpr": "pbiFormat(datum.value,''MM'')",
"title": "",
"labelFontSize": 8,
"labelSeparation": 1,
"tickCount": 10,
"domainColor": {
"expr": "indata(''data_0'',''CategoryRank'',2) ? ''gray'': ''transparent'' "
}
}
},
"y": {
"type": "quantitative",
"axis": {
"labelFontSize": 8,
"title": "",
"domainColor": {
"expr": "indata(''data_0'',''CategoryRank'',2) ? ''gray'': ''transparent'' "
}
},
"scale": {
"type": "linear",
"zero": false
}
}
}
},
{
"transform": [
{
"filter": "datum.CategoryRank == 3"
}
],
"width": 180,
"height": 120,
"layer": [
{
"transform": [
{
"filter": "datum.filasPorCategoria== 1"
}
],
"layer": [
{
"mark": {
"type": "rect",
"align": "left",
"fill": "gray",
"opacity": 0.1,
"height": 170,
"width": 365,
"yOffset": 60,
"xOffset": -180,
"cornerRadiusTopLeft": 15,
"cornerRadiusBottomLeft": 15
}
},
{
"mark": {
"type": "rect",
"align": "left",
"color": {
"expr": "NombreDeMetrica==''Total Cost''? datum.SentimentColor>0? ''firebrick'':''green'': datum.SentimentColor<0? ''firebrick'':''green''"
},
"height": 170,
"width": 15,
"yOffset": 60,
"xOffset": 180,
"cornerRadiusTopRight": 15,
"cornerRadiusBottomRight": 15
}
},
{
"mark": {
"type": "text",
"color": "black",
"fontWeight": 700,
"fontSize": 15
},
"encoding": {
"text": {
"value": {
"expr": "NombreDeMetrica"
}
},
"x": {
"value": -100
},
"y": {
"value": 40
}
}
},
{
"mark": {
"type": "text",
"align": "left",
"color": "black",
"fontWeight": 600,
"fontSize": 14
},
"encoding": {
"text": {
"field": "__title__"
},
"x": {
"value": -160
},
"y": {
"value": -52
}
}
},
{
"mark": {
"type": "text",
"color": "black",
"align": "left",
"fontWeight": 400,
"fontSize": 10
},
"encoding": {
"text": {
"field": "__date__"
},
"x": {
"value": -160
},
"y": {
"value": -35
}
}
},
{
"mark": {
"type": "text",
"color": {
"expr": "NombreDeMetrica==''Total Cost''? datum.SentimentColor>0? ''firebrick'':''green'': datum.SentimentColor<0? ''firebrick'':''green''"
},
"fontWeight": 700,
"fontSize": 25
},
"encoding": {
"text": {
"value": {
"expr": "pbiFormat(datum.totalDeVentas,formatString,{value: datum.totalDeVentas>=1e12? 1e12: datum.totalDeVentas>=1e9? 1e9: datum.totalDeVentas>= 1e6? 1e6: datum.totalDeVentas>=1e3? 1e3: 1,precision:0 })"
}
},
"x": {
"value": -100
},
"y": {
"value": 70
}
}
}
]
},
{
"mark": {
"type": "line",
"strokeWidth": 1.5,
"color": "black",
"opacity": 0.7,
"tooltip": true,
"point": {
"stroke": "white",
"strokeWidth": 0.5,
"size": 20,
"fill": "black"
}
},
"encoding": {
"y": {
"field": "MetricKPIValue"
}
}
},
{
"transform": [
{
"regression": "MetricKPIValue",
"on": "End Of Month"
},
{
"window": [
{
"field": "MetricKPIValue",
"op": "first_value",
"as": "first_value"
}
]
},
{
"window": [
{
"field": "MetricKPIValue",
"op": "last_value",
"as": "last_value"
}
],
"frame": [
null,
null
]
},
{
"calculate": "datum.last_value-datum.first_value",
"as": "SentimentColor"
}
],
"mark": {
"type": "line",
"strokeWidth": 1.5,
"strokeDash": [
4,
8
],
"color": {
"expr": "NombreDeMetrica==''Total Cost''? datum.SentimentColor>0? ''firebrick'':''green'': datum.SentimentColor<0? ''firebrick'':''green''"
}
},
"encoding": {
"x": {
"field": "End Of Month",
"type": "ordinal"
},
"y": {
"field": "MetricKPIValue",
"type": "quantitative"
}
}
}
],
"encoding": {
"x": {
"field": "End Of Month",
"timeUnit": "monthdate",
"type": "nominal",
"axis": {
"labelExpr": "pbiFormat(datum.value,''MM'')",
"title": "",
"labelFontSize": 8,
"labelSeparation": 1,
"tickCount": 10,
"domainColor": {
"expr": "indata(''data_0'',''CategoryRank'',3) ? ''gray'': ''transparent'' "
}
}
},
"y": {
"type": "quantitative",
"axis": {
"labelFontSize": 8,
"title": "",
"domainColor": {
"expr": "indata(''data_0'',''CategoryRank'',3) ? ''gray'': ''transparent'' "
}
},
"scale": {
"type": "linear",
"zero": false
}
}
}
},
{
"transform": [
{
"filter": "datum.CategoryRank == 4"
}
],
"width": 180,
"height": 120,
"layer": [
{
"transform": [
{
"filter": "datum.filasPorCategoria== 1"
}
],
"layer": [
{
"mark": {
"type": "rect",
"align": "left",
"fill": "gray",
"opacity": 0.1,
"height": 170,
"width": 365,
"yOffset": 60,
"xOffset": -180,
"cornerRadiusTopLeft": 15,
"cornerRadiusBottomLeft": 15
}
},
{
"mark": {
"type": "rect",
"align": "left",
"color": {
"expr": "NombreDeMetrica==''Total Cost''? datum.SentimentColor>0? ''firebrick'':''green'': datum.SentimentColor<0? ''firebrick'':''green''"
},
"height": 170,
"width": 15,
"yOffset": 60,
"xOffset": 180,
"cornerRadiusTopRight": 15,
"cornerRadiusBottomRight": 15
}
},
{
"mark": {
"type": "text",
"color": "black",
"fontWeight": 700,
"fontSize": 15
},
"encoding": {
"text": {
"value": {
"expr": "NombreDeMetrica"
}
},
"x": {
"value": -100
},
"y": {
"value": 40
}
}
},
{
"mark": {
"type": "text",
"align": "left",
"color": "black",
"fontWeight": 600,
"fontSize": 14
},
"encoding": {
"text": {
"field": "__title__"
},
"x": {
"value": -160
},
"y": {
"value": -52
}
}
},
{
"mark": {
"type": "text",
"color": "black",
"align": "left",
"fontWeight": 400,
"fontSize": 10
},
"encoding": {
"text": {
"field": "__date__"
},
"x": {
"value": -160
},
"y": {
"value": -35
}
}
},
{
"mark": {
"type": "text",
"color": {
"expr": "NombreDeMetrica==''Total Cost''? datum.SentimentColor>0? ''firebrick'':''green'': datum.SentimentColor<0? ''firebrick'':''green''"
},
"fontWeight": 700,
"fontSize": 25
},
"encoding": {
"text": {
"value": {
"expr": "pbiFormat(datum.totalDeVentas,formatString,{value: datum.totalDeVentas>=1e12? 1e12: datum.totalDeVentas>=1e9? 1e9: datum.totalDeVentas>= 1e6? 1e6: datum.totalDeVentas>=1e3? 1e3: 1,precision:0 })"
}
},
"x": {
"value": -100
},
"y": {
"value": 70
}
}
}
]
},
{
"mark": {
"type": "line",
"strokeWidth": 1.5,
"color": "black",
"opacity": 0.7,
"tooltip": true,
"point": {
"stroke": "white",
"strokeWidth": 0.5,
"size": 20,
"fill": "black"
}
},
"encoding": {
"y": {
"field": "MetricKPIValue"
}
}
},
{
"transform": [
{
"regression": "MetricKPIValue",
"on": "End Of Month"
},
{
"window": [
{
"field": "MetricKPIValue",
"op": "first_value",
"as": "first_value"
}
]
},
{
"window": [
{
"field": "MetricKPIValue",
"op": "last_value",
"as": "last_value"
}
],
"frame": [
null,
null
]
},
{
"calculate": "datum.last_value-datum.first_value",
"as": "SentimentColor"
}
],
"mark": {
"type": "line",
"strokeWidth": 1.5,
"strokeDash": [
4,
8
],
"color": {
"expr": "NombreDeMetrica==''Total Cost''? datum.SentimentColor>0? ''firebrick'':''green'': datum.SentimentColor<0? ''firebrick'':''green''"
}
},
"encoding": {
"x": {
"field": "End Of Month",
"type": "ordinal"
},
"y": {
"field": "MetricKPIValue",
"type": "quantitative"
}
}
}
],
"encoding": {
"x": {
"field": "End Of Month",
"timeUnit": "monthdate",
"type": "nominal",
"axis": {
"labelExpr": "pbiFormat(datum.value,''MM'')",
"title": "",
"labelFontSize": 8,
"labelSeparation": 1,
"tickCount": 10,
"domainColor": {
"expr": "indata(''data_0'',''CategoryRank'',4) ? ''gray'': ''transparent'' "
}
}
},
"y": {
"type": "quantitative",
"axis": {
"labelFontSize": 8,
"title": "",
"domainColor": {
"expr": "indata(''data_0'',''CategoryRank'',4) ? ''gray'': ''transparent'' "
}
},
"scale": {
"type": "linear",
"zero": false
}
}
}
},
{
"transform": [
{
"filter": "datum.CategoryRank == 5"
}
],
"width": 180,
"height": 120,
"layer": [
{
"transform": [
{
"filter": "datum.filasPorCategoria== 1"
}
],
"layer": [
{
"mark": {
"type": "rect",
"align": "left",
"fill": "gray",
"opacity": 0.1,
"height": 170,
"width": 365,
"yOffset": 60,
"xOffset": -180,
"cornerRadiusTopLeft": 15,
"cornerRadiusBottomLeft": 15
}
},
{
"mark": {
"type": "rect",
"align": "left",
"color": {
"expr": "NombreDeMetrica==''Total Cost''? datum.SentimentColor>0? ''firebrick'':''green'': datum.SentimentColor<0? ''firebrick'':''green''"
},
"height": 170,
"width": 15,
"yOffset": 60,
"xOffset": 180,
"cornerRadiusTopRight": 15,
"cornerRadiusBottomRight": 15
}
},
{
"mark": {
"type": "text",
"color": "black",
"fontWeight": 700,
"fontSize": 15
},
"encoding": {
"text": {
"value": {
"expr": "NombreDeMetrica"
}
},
"x": {
"value": -100
},
"y": {
"value": 40
}
}
},
{
"mark": {
"type": "text",
"align": "left",
"color": "black",
"fontWeight": 600,
"fontSize": 14
},
"encoding": {
"text": {
"field": "__title__"
},
"x": {
"value": -160
},
"y": {
"value": -52
}
}
},
{
"mark": {
"type": "text",
"color": "black",
"align": "left",
"fontWeight": 400,
"fontSize": 10
},
"encoding": {
"text": {
"field": "__date__"
},
"x": {
"value": -160
},
"y": {
"value": -35
}
}
},
{
"mark": {
"type": "text",
"color": {
"expr": "NombreDeMetrica==''Total Cost''? datum.SentimentColor>0? ''firebrick'':''green'': datum.SentimentColor<0? ''firebrick'':''green''"
},
"fontWeight": 700,
"fontSize": 25
},
"encoding": {
"text": {
"value": {
"expr": "pbiFormat(datum.totalDeVentas,formatString,{value: datum.totalDeVentas>=1e12? 1e12: datum.totalDeVentas>=1e9? 1e9: datum.totalDeVentas>= 1e6? 1e6: datum.totalDeVentas>=1e3? 1e3: 1,precision:0 })"
}
},
"x": {
"value": -100
},
"y": {
"value": 70
}
}
}
]
},
{
"mark": {
"type": "line",
"strokeWidth": 1.5,
"color": "black",
"opacity": 0.7,
"tooltip": true,
"point": {
"stroke": "white",
"strokeWidth": 0.5,
"size": 20,
"fill": "black"
}
},
"encoding": {
"y": {
"field": "MetricKPIValue"
}
}
},
{
"transform": [
{
"regression": "MetricKPIValue",
"on": "End Of Month"
},
{
"window": [
{
"field": "MetricKPIValue",
"op": "first_value",
"as": "first_value"
}
]
},
{
"window": [
{
"field": "MetricKPIValue",
"op": "last_value",
"as": "last_value"
}
],
"frame": [
null,
null
]
},
{
"calculate": "datum.last_value-datum.first_value",
"as": "SentimentColor"
}
],
"mark": {
"type": "line",
"strokeWidth": 1.5,
"strokeDash": [
4,
8
],
"color": {
"expr": "NombreDeMetrica==''Total Cost''? datum.SentimentColor>0? ''firebrick'':''green'': datum.SentimentColor<0? ''firebrick'':''green''"
}
},
"encoding": {
"x": {
"field": "End Of Month",
"type": "ordinal"
},
"y": {
"field": "MetricKPIValue",
"type": "quantitative"
}
}
}
],
"encoding": {
"x": {
"field": "End Of Month",
"timeUnit": "monthdate",
"type": "nominal",
"axis": {
"labelExpr": "pbiFormat(datum.value,''MM'')",
"title": "",
"labelFontSize": 8,
"labelSeparation": 1,
"tickCount": 10,
"domainColor": {
"expr": "indata(''data_0'',''CategoryRank'',5) ? ''gray'': ''transparent'' "
}
}
},
"y": {
"type": "quantitative",
"axis": {
"labelFontSize": 8,
"title": "",
"domainColor": {
"expr": "indata(''data_0'',''CategoryRank'',5) ? ''gray'': ''transparent'' "
}
},
"scale": {
"type": "linear",
"zero": false
}
}
}
},
{
"transform": [
{
"filter": "datum.CategoryRank == 6"
}
],
"width": 180,
"height": 120,
"layer": [
{
"transform": [
{
"filter": "datum.filasPorCategoria== 1"
}
],
"layer": [
{
"mark": {
"type": "rect",
"align": "left",
"fill": "gray",
"opacity": 0.1,
"height": 170,
"width": 365,
"yOffset": 60,
"xOffset": -180,
"cornerRadiusTopLeft": 15,
"cornerRadiusBottomLeft": 15
}
},
{
"mark": {
"type": "rect",
"align": "left",
"color": {
"expr": "NombreDeMetrica==''Total Cost''? datum.SentimentColor>0? ''firebrick'':''green'': datum.SentimentColor<0? ''firebrick'':''green''"
},
"height": 170,
"width": 15,
"yOffset": 60,
"xOffset": 180,
"cornerRadiusTopRight": 15,
"cornerRadiusBottomRight": 15
}
},
{
"mark": {
"type": "text",
"color": "black",
"fontWeight": 700,
"fontSize": 15
},
"encoding": {
"text": {
"value": {
"expr": "NombreDeMetrica"
}
},
"x": {
"value": -100
},
"y": {
"value": 40
}
}
},
{
"mark": {
"type": "text",
"align": "left",
"color": "black",
"fontWeight": 600,
"fontSize": 14
},
"encoding": {
"text": {
"field": "__title__"
},
"x": {
"value": -160
},
"y": {
"value": -52
}
}
},
{
"mark": {
"type": "text",
"color": "black",
"align": "left",
"fontWeight": 400,
"fontSize": 10
},
"encoding": {
"text": {
"field": "__date__"
},
"x": {
"value": -160
},
"y": {
"value": -35
}
}
},
{
"mark": {
"type": "text",
"color": {
"expr": "NombreDeMetrica==''Total Cost''? datum.SentimentColor>0? ''firebrick'':''green'': datum.SentimentColor<0? ''firebrick'':''green''"
},
"fontWeight": 700,
"fontSize": 25
},
"encoding": {
"text": {
"value": {
"expr": "pbiFormat(datum.totalDeVentas,formatString,{value: datum.totalDeVentas>=1e12? 1e12: datum.totalDeVentas>=1e9? 1e9: datum.totalDeVentas>= 1e6? 1e6: datum.totalDeVentas>=1e3? 1e3: 1,precision:0 })"
}
},
"x": {
"value": -100
},
"y": {
"value": 70
}
}
}
]
},
{
"mark": {
"type": "line",
"strokeWidth": 1.5,
"color": "black",
"opacity": 0.7,
"tooltip": true,
"point": {
"stroke": "white",
"strokeWidth": 0.5,
"size": 20,
"fill": "black"
}
},
"encoding": {
"y": {
"field": "MetricKPIValue"
}
}
},
{
"transform": [
{
"regression": "MetricKPIValue",
"on": "End Of Month"
},
{
"window": [
{
"field": "MetricKPIValue",
"op": "first_value",
"as": "first_value"
}
]
},
{
"window": [
{
"field": "MetricKPIValue",
"op": "last_value",
"as": "last_value"
}
],
"frame": [
null,
null
]
},
{
"calculate": "datum.last_value-datum.first_value",
"as": "SentimentColor"
}
],
"mark": {
"type": "line",
"strokeWidth": 1.5,
"strokeDash": [
4,
8
],
"color": {
"expr": "NombreDeMetrica==''Total Cost''? datum.SentimentColor>0? ''firebrick'':''green'': datum.SentimentColor<0? ''firebrick'':''green''"
}
},
"encoding": {
"x": {
"field": "End Of Month",
"type": "ordinal"
},
"y": {
"field": "MetricKPIValue",
"type": "quantitative"
}
}
}
],
"encoding": {
"x": {
"field": "End Of Month",
"timeUnit": "monthdate",
"type": "nominal",
"axis": {
"labelExpr": "pbiFormat(datum.value,''MM'')",
"title": "",
"labelFontSize": 8,
"labelSeparation": 1,
"tickCount": 10,
"domainColor": {
"expr": "indata(''data_0'',''CategoryRank'',6) ? ''gray'': ''transparent'' "
}
}
},
"y": {
"type": "quantitative",
"axis": {
"labelFontSize": 8,
"title": "",
"domainColor": {
"expr": "indata(''data_0'',''CategoryRank'',6) ? ''gray'': ''transparent'' "
}
},
"scale": {
"type": "linear",
"zero": false
}
}
}
}
],
"resolve": {
"scale": {
"y": "shared"
}
},
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"usermeta": {
"information": {
"name": "Explorador de KPIs por Categoría",
"description": "Plantilla interactiva que te permite visualizar y comparar tendencias de tus indicadores clave de rendimiento según cualquier categoría. Selecciona dinámicamente la métrica y la categoría para ver la evolución mensual, detectar patrones y tomar decisiones basadas en datos de manera ágil y clara. autor: Cristobal Salcedo Beltran"
},
"config": "{\n \"view\": {\n \"stroke\": \"transparent\"\n },\n \"line\": {\n \"strokeWidth\": 3,\n \"strokeCap\": \"round\",\n \"strokeJoin\": \"round\"\n },\n \"symbol\": {\n \"strokeWidth\": 1.5,\n \"size\": 50\n },\n \"text\": {\n \"font\": \"Times New Roman\",\n \"fontSize\": 12,\n \"fill\": \"#605E5C\"\n },\n \"axis\": {\n \"ticks\": true,\n \"tickSize\":3,\n \"tickWidth\":0.1,\n \"grid\": false,\n \"domain\": true,\n \"domainWidth\":0.1,\n \"labelColor\": \"#605E5C\",\n \"labelFontSize\": 12,\n \"titleFont\": \"Times New Roman\",\n \"titleColor\": \"#252423\",\n \"titleFontSize\": 16,\n \"titleFontWeight\": \"normal\"\n },\n \"axisQuantitative\": {\n \"tickCount\": 3,\n \"grid\": true,\n \"gridColor\": \"#C8C6C4\",\n \"gridDash\": [\n 1,\n 5\n ],\n \"labelFlush\": false\n },\n \"axisX\": {\n \"labelPadding\": 5\n },\n \"axisY\": {\n \"labelPadding\": 4,\n \"labelExpr\": \"pbiFormatAutoUnit(datum.value,formatString)\"\n }\n}",
"deneb": {
"provider": "vegaLite",
"providerVersion": "5.16.3"
},
"interactivity": {
"tooltip": true,
"contextMenu": false,
"selection": false,
"highlight": false
}
}
}