Get the Min score over the last 12 ROLLING months
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2023 04:04 AM - edited ‎11-23-2023 04:10 AM
Hello,
I have a requirement for a formula indicator that should retrieve the minimum % score of the last 12 months. The issue I'm facing is that in the analytics hub, it shows the MIN result, which is 82%, and this score is the MIN of 2022, not 2023, which has a result of 83%. I want to set it up so that if I choose the 2022 months, the MIN score remains 82%, and if I choose 2023, it should be 83%, and so on for subsequent years. Additionally, I need the score to be displayed instead of showing NO SCORE
Here is my formula script :
var year = score_start.getYear();
var day= score_start.getDayOfMonthLocalTime();
var lowestScore =100;
for (var month = 1; month <= 12; month++) {
var monthStr = month.toString();
if (month < 10) {
monthStr = '0' + month; }
else {
monthStr = '' + month;
}
var dateStr = year + '-' + monthStr + '-' + day;
var score = pa.getScore($[[My % indicator],new GlideDateTime(dateStr));
if (score < lowestScore) {
lowestScore = score;
}
}
lowestScore;
Display for 2022 :
Display for 2023 :
Did I miss something in my script? Normally, I tried to loop through the 12 months of the year, format the date, add it to pa.getscore, return the minimum value for each month, and finally retrieve the lowest score.