Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Rohini
Helper I
Helper I

Power Query Editor - Current Month Issue

Reporting values during a current month requires pulling data pertaining to previous month i.e., during March, I need to extract data from the field [Feb 2020], in April, I need to extract data from the field [Mar 2020] and so on...

 

The following formula works in a query but not in power query - 

 

Current_Month = If (MONTH(TODAY())=3, [Feb 2020], (
            If (MONTH(TODAY())=4, [Mar 2020], (
If (MONTH(TODAY())=5, [Apr 2020], (
            If (MONTH(TODAY())=6, [May 2020], (
            If (MONTH(TODAY())=7, [Jun 2020], (
            If (MONTH(TODAY())=8, [Jul 2020], (
            If (MONTH(TODAY())=9, [Aug 2020], (
            If (MONTH(TODAY())=10, [Sep 2020], (
If (MONTH(TODAY())=11, [Oct 2020], (
If (MONTH(TODAY())=12, [Nov 2020], "999999999")))))))))))

))))))))
 
Can someone help me on how to extract the current month in power query editor?
1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

Hi @Rohini 

for Power Query use Date.Month(DateTime.LocalNow()) function

like

= if Date.Month(DateTime.LocalNow())=3 
then [Feb 2020]
else if Date.Month(DateTime.LocalNow())=4
then [Mar 2020]
else "999999999" 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

This seems like DAX to me. Are looking for M code ?

https://docs.microsoft.com/en-us/powerquery-m/datetime-localnow

https://docs.microsoft.com/en-us/powerquery-m/date-month

https://docs.microsoft.com/en-us/powerquery-m/date-year

 

In DAX we could have used these with date calendar

 

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last MTD (complete) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-1,MONTH))))
last year MTD (complete) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-12,MONTH))))
last year MTD Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-12,MONTH)))
trailing Month= CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Month))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
az38
Community Champion
Community Champion

Hi @Rohini 

for Power Query use Date.Month(DateTime.LocalNow()) function

like

= if Date.Month(DateTime.LocalNow())=3 
then [Feb 2020]
else if Date.Month(DateTime.LocalNow())=4
then [Mar 2020]
else "999999999" 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.