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
ohb60
Frequent Visitor

Previous month name in a empty table

Hi PBI expert,

 

I'm a beginner and I'm using Json file with relative date (month -1) and I'd like to find the name of the previous month from today's date...

 

So this is how I find the actual month...and it display "mars" (maybe not the best method...)
But what I want is to display "february" ...how can I do that ? 

= let
Source = Table.FromRows({{Date.MonthName(DateTime.LocalNow())}},{"Month"})
in
Source
1 ACCEPTED SOLUTION
ohb60
Frequent Visitor

Finally I found something that works : 

 

PrevMon = FORMAT(EDATE(NOW();-1);"MMMM")

Smiley Happy

 

Thanks everyone !

View solution in original post

7 REPLIES 7
Greg_Deckler
Community Champion
Community Champion

Try this:

 

Measure 2 = 
VAR __currentMonth = MONTH(EOMONTH(TODAY(),0))
VAR __previousMonth = IF(__currentMonth = 1,12,__currentMonth - 1)
VAR __previousYear = IF(__currentMonth = 1,YEAR(TODAY()) - 1,YEAR(TODAY()))
RETURN
FORMAT(DATE(__previousYear,__previousMonth,1),"mmm")


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...


@Greg_Deckler wrote:

Try this:

 

Measure 2 = 
VAR __currentMonth = MONTH(EOMONTH(TODAY(),0))
VAR __previousMonth = IF(__currentMonth = 1,12,__currentMonth - 1)
VAR __previousYear = IF(__currentMonth = 1,YEAR(TODAY()) - 1,YEAR(TODAY()))
RETURN
FORMAT(DATE(__previousYear,__previousMonth,1),"mmm")


Thank you Greg but it's not working for me...I have this error when I try to validate this new measure :

 

La syntaxe pour '.0' est incorrecte. (DAX(VAR __currentMonth = MONTH(EOMONTH(TODAY().0))VAR __previousMonth = IF(__currentMonth = 1.12,__currentMonth - 1)VAR __previousYear = IF(__currentMonth = 1.YEAR(TODAY()) - 1.YEAR(TODAY()))RETURNFORMAT(DATE(__previousYear,__previousMonth.1),"mmm"))).

Greg_Deckler
Community Champion
Community Champion

Does this have to be done in M or can you do it in DAX?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Both method interest me but maybe I should say : the most simple one 🙂

@ohb60  Please try this to get the previous month name 

Power Query Editor (M-Code)

= Table.AddColumn(#"Added Custom", "PrevMonth", each Date.MonthName(Date.AddMonths([hiredate],-1)))

DAX

PrevMon = FORMAT(EDATE(emp[hiredate],-1),"MMMM")

 





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion





@PattemManohar wrote:

@ohb60  Please try this to get the previous month name 

Power Query Editor (M-Code)

= Table.AddColumn(#"Added Custom", "PrevMonth", each Date.MonthName(Date.AddMonths([hiredate],-1)))

DAX

PrevMon = FORMAT(EDATE(emp[hiredate],-1),"MMMM")

 


Thank you for this but I can't make it work either : 

 

I wrote this in my new measure : 

PrevMon = FORMAT(EDATE(MAJ[Update];-1);"MMMM")

I got this error message : 

It is not possible to determine a single value for the 'Update' column of the 'Update' table. This can occur when a measurement formula refers to a column that contains many values, without specifying an aggregation such as min, max, count, or sum to obtain a single result.

 

Here's the code I have in my 'Update' column  : 

let
    Source = Table.FromRows({{DateTime.LocalNow()}},{"Update"})
in
    Source

 

ohb60
Frequent Visitor

Finally I found something that works : 

 

PrevMon = FORMAT(EDATE(NOW();-1);"MMMM")

Smiley Happy

 

Thanks everyone !

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.