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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply

previous date

Hi ,

 

Im using this for current month and year which is working fine.

 

currentdate=(Date.ToText(DateTime.Date(DateTime.LocalNow()),"MMyyyy"))

Output is =112022

 

now i want to get prevoius month 

 

Pdate=(Date.ToText(DateTime.Date(DateTime.LocalNow()),"MMyyyy")) -1 

but its not working please advise.

 

 

1 ACCEPTED SOLUTION
Samarth_18
Community Champion
Community Champion

Hi @faheem_Latif_BI ,

 

Please try below mquery code in custom column:-

Text.PadStart(Text.From(Date.Month(DateTime.LocalNow())-1),2,"0")&Text.From(Date.Year(DateTime.LocalNow()))

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

View solution in original post

7 REPLIES 7
wdx223_Daniel
Super User
Super User

Pdate=Date.ToText(Date.AddMonths(DateTime.Date(DateTime.LocalNow()),-1),"MMyyyy")) 

Thanks for reply im using like this but giving me error 

 

Table.AddColumn(#"Added Custom", "Previous_MonthYear", each Date.ToText(Text.PadStart(Text.From(Date.Month(DateTime.LocalNow())-1),2,"0")&Text.From(Date.Year(DateTime.LocalNow())),"MMyyyy"))

Could you please share the error?

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

faheem_Latif_BI_0-1667893463836.png

 

@faheem_Latif_BI Please try this:-

#"Added Custom" = Table.AddColumn(#"Added Custom", "Previous_MonthYear", each Text.PadStart( Text.From(Date.Month(DateTime.LocalNow())-1),2,"0")&Text.From(Date.Year(DateTime.LocalNow())))
in
    #"Added Custom"

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

smart 18

 

UR star

Samarth_18
Community Champion
Community Champion

Hi @faheem_Latif_BI ,

 

Please try below mquery code in custom column:-

Text.PadStart(Text.From(Date.Month(DateTime.LocalNow())-1),2,"0")&Text.From(Date.Year(DateTime.LocalNow()))

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.