mamuewue
11-06-2023Cloud Apps
Dynamic Value-Names in Pivot Table
Hi folks, I am trying to name the "value" columns in a pivot table in a dynamic way. I have a table that compares the last month data, with the data the month before. Right now, on the 6th of Novemb...
- 11-14-2023
Hi mamuewue,
The widget script below changes the titles of items in the 'values panel' dynamically based on the current month. It looks for value panel items that are named 'last month MRR' & 'month before last' and replaces them with '<last month's name> MRR' and '<month before lasts name> MRR'.
widget.on('initialized', (w, args) => { const month = ["January","February","March","April","May","June","July","August","September","October","November","December"] var x = new Date() x.setDate(1) x.setMonth(x.getMonth()-1) var y = new Date() y.setDate(1) y.setMonth(y.getMonth()-2) const items = w.metadata.panel('values').items for (let i = 0; i < items.length; i++) { const item = items[i] if (item.jaql.title === 'last month MRR') { item.jaql.title = `${month[x.getMonth()]} MRR` } if (item.jaql.title === 'month before last') { item.jaql.title = `${month[y.getMonth()]} MRR` } } })
Let me know if this works for you?
Thanks,
Daniel
RAPID BI
RAPID BI - Sisense Professional Services | Implementations | Custom Add-ons