# Power Query how to get dynamic month no. in a filter function



## jccnz (May 28, 2019)

Hi All, I'm new here. 
I have a power query filter question, I want to filter the month as last year of this month (ie current month no.).  I  filtered the year but I want to make the month dynamic.
Using this filter function how to make Date.Month([Calendar]) = calculate as current month no.
= Table.SelectRows(#"Filtered Rows", each Date.Month([Calendar]) = 5)
Thanks


----------



## sandy666 (May 29, 2019)

maybe Date.Month(DateTime.LocalNow())


----------



## jccnz (May 29, 2019)

sandy666 said:


> maybe Date.Month(DateTime.LocalNow())



Thanks Sandy but doesn't work thou...


----------



## sandy666 (May 29, 2019)

so your description isn't clear

= Table.SelectRows(#"Filtered Rows", each Date.Month([Calendar]) = *5*)

*Date.Month(DateTime.LocalNow())* will give you number of actual month = 5

so: = Table.SelectRows(#"Filtered Rows", each Date.Month([Calendar]) = Date.Month(DateTime.LocalNow()))

btw. value of Date.Month(DateTime.LocalNow()) is taken from the system date

maybe try explain more....


----------



## jccnz (May 29, 2019)

Woo it works now didn't work before.  Thank you so much


----------



## sandy666 (May 29, 2019)

It's magic !!! 
	

	
	
		
		

		
			





Have  a nice day


----------



## jccnz (Jun 6, 2019)

Hi again, 
my reporting need to be today()-1 so when the end of the month for example 1st Jul, I still need to report 30th Jun, Date.Month(DateTime.LocalNow())) still need to be 6 not 7, how to - 1 day? in this statement?
Thanks


----------



## sandy666 (Jun 6, 2019)

maybe try: Date.AddDays(Date.From(DateTime.LocalNow()),-1)


----------

