Forum Discussion

rahuldhomane's avatar
11-11-2022
Solved

How can we show previous 12 month on selecting a particular month in filter

Hi harikm007 , I want to show previous 12 months of data from a selection I make on a month filter. But the user should be able to change the month and the previous 12 month will get updated based ...
  • Harry's avatar
    11-14-2022

    Hello rahuldhomane ,

    You can try below widget script to display previous 12 months of data from selected month.  Here update the variable 'monthFilterName' with name of your filter. 

    
    widget.on("beforequery", function(se,ev) 
    {
    	var monthFilterName = "Months in Date of Joining"; 
    	var numberofPrevMonths = 10
    	
    	monthFilter = ev.query.metadata.find(el => el.jaql.title == monthFilterName && el.panel == 'scope')
    	
    	if(monthFilter)
    	{
    		
    		prevMonth = new Date(monthFilter.jaql.filter.members[0])
    		for(i = 1; i < numberofPrevMonths; i++)
    		{
      			prevMonth = new Date(prevMonth.setMonth(prevMonth.getMonth()-1))
    			preMonthStr =  prevMonth.getFullYear() + '-' + ('0' + (prevMonth.getMonth()+1)).slice(-2) +  "-01T00:00:00" //prevMonth.toISOString();
    			
    			monthFilter.jaql.filter.members.unshift(preMonthStr)
    		}
    	}
    	
    });
    

     

    Also if you add Date Range Slider plugin, it will give you an option to select any date range in addition to previous 12 months.

    Please let me know if you have any questions

     

    Always here to help,
    Harry from QBeeQ

    QBeeQ - Gold Implementation and Development Partner
    www.qbeeq.pl