top of page

Sort bar/columns/breakby manually




This script is to sort items in X-axis manually. Widget will display bar/columns in the order you specified in 'categories' list


var categories= ['Jan','Feb','Mar','Apr','May','Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
widget.on('queryend',function(se,ev){
	ev.rawResult.values.sort(function(a, b){
		var aIndex = categories.indexOf(a[0].data);
		var bIndex = categories.indexOf(b[0].data);
						
		if (aIndex < bIndex)
			return -1;
		if (aIndex > bIndex)
			return 1;
							
		return 0;
	})
})


If you need to sort items in 'Break by', use below script


breakby = ['West', 'Midwest', 'South', 'Northeast', 'Unknown']
widget.on('processresult',function(se,ev){
	ev.result.series.sort(function(a,b){
		if (breakby.indexOf(a.name) < breakby.indexOf(b.name)) {
			return -1
		}
		else if (breakby.indexOf(a.name)>breakby.indexOf(b.name)) {
			return 1
		}
		return 0;
	});
})



534 views1 comment

1 comentario

Obtuvo 0 de 5 estrellas.
Aún no hay calificaciones

Agrega una calificación
scoughlan
02 sept 2024

How could I achieve this in a pivot table where the Month field is just one of many columns in the table?

Me gusta
BI Next Level white logo

BI Next Level is your trusted resource for BI customization, data solutions, and expert insights. Explore practical tips, scripts, and tutorials for tools like Sisense, Python, and SQL. Let’s transform your data into impactful insights together.

Quick Links
Connect with us
Copyright © 2024. All Rights Reserved. Designed, Developed & Maintained  by Intertoons
bottom of page