Thanks @Taoufiq_Zarra for your reply. This solution is only working for current and Prior years only because you are fetching data based on maxdate but I have data from 2017 to 2021 for other years this solution is not working. Can you please help me to get same kind of output for 2017 to 2021.
@Taoufiq_Zarra Thanks for your new solution but this is taking more time to load data usually it takes 1minute but now it is taking more than 25mins. Can you please help me to get other simplified solution.