Forum Discussion

Uzi2019's avatar
Uzi2019
Community Champion
1 year ago
Solved

Power query not generating Last Month

Hi Team,

I dont know what happend to this query. this is not generating Dec 2024 month . It was showing correct information till last year in Dec2024 showing data till Nov 2023..

 

Source= 1/1/2021

Custom= = List.Generate(()=>[x=#date(2021,1,1),i=0], each [i]< (Date.Month(DateTime.LocalNow()) - Date.Month(Source)+12*(Date.Year(DateTime.LocalNow())-Date.Year(Source))-1), each [i=[i]+1,x=Date.AddMonths([x],1)], each [x])

 

 

 

Showing Max Nov 2024.  need Dec2024 as well.

 

Thanks in advance!

 

 

  • Hi Uzi2019 ,
    To ensure the last month (e.g., December 2024) is included, try adjusting the formula like this:

    Source = #date(2021, 1, 1),
    
    Custom = List.Generate(
        () => [x = #date(2021, 1, 1), i = 0], 
        each [i] < (Date.Month(DateTime.LocalNow()) + 12 * (Date.Year(DateTime.LocalNow()) - Date.Year(Source)) - 1), 
        each [i = [i] + 1, x = Date.AddMonths([x], 1)], 
        each [x]
    )
    

    As you can see now, the last month is DEC-2024:

     

2 Replies

  • Hi Uzi2019 ,
    To ensure the last month (e.g., December 2024) is included, try adjusting the formula like this:

    Source = #date(2021, 1, 1),
    
    Custom = List.Generate(
        () => [x = #date(2021, 1, 1), i = 0], 
        each [i] < (Date.Month(DateTime.LocalNow()) + 12 * (Date.Year(DateTime.LocalNow()) - Date.Year(Source)) - 1), 
        each [i = [i] + 1, x = Date.AddMonths([x], 1)], 
        each [x]
    )
    

    As you can see now, the last month is DEC-2024:

     

    • Uzi2019's avatar
      Uzi2019
      Community Champion

      Hi Bibiano_Geraldo 

       

      Thank you for your support. but I understood the logic of M query. It was showing -2 month . s\So when Feb comes it auto shows Dec by default.