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
Anonymous
Not applicable

Custom Column Power Query

Hi Experts

 

need a custom column to do the following if the date is current month -1 then "Actual" ie. Feb 21 and all historical months in year and any future period then return "4YOP".

 

 

1 ACCEPTED SOLUTION

@Anonymous , you have shared your formula. I copy passed same in my file and changed the date and it worked , only in bold need to be changed

if [Sales Date] >= Date.StartOfMonth(Date.AddMonths(Date.From(DateTime.LocalNow()),-1)) and [Date] <= Date.EndOfMonth(Date.AddMonths(Date.From(DateTime.LocalNow()),-1))
then "Actual" else "4YOP"

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

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@Anonymous , Try a new column like

 

if [Date] >= Date.StartOfMonth(Date.AddMonths(Date.From(DateTime.LocalNow()),-1)) and [Date] <= Date.EndOfMonth(Date.AddMonths(Date.From(DateTime.LocalNow()),-1))
then "Actual" else "4YOP"

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
Anonymous
Not applicable

Getting an error here "Actual" - message Token Eof expected? - or alternatively on then

@Anonymous , you have shared your formula. I copy passed same in my file and changed the date and it worked , only in bold need to be changed

if [Sales Date] >= Date.StartOfMonth(Date.AddMonths(Date.From(DateTime.LocalNow()),-1)) and [Date] <= Date.EndOfMonth(Date.AddMonths(Date.From(DateTime.LocalNow()),-1))
then "Actual" else "4YOP"

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
Anonymous
Not applicable

Apologies my fault... i had IF as opposed to if.... thanks Amit

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.