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

View all the Fabric Data Days sessions on demand. View schedule

Reply
MBenson415
Frequent Visitor

Replace Dates at Beginning of Month with Last Day of Previous Month

Hello,

 

I am attempting to use Power Query to do the following in plain langue: If a date appears at the beginning of the month, replace it with the last date of the previous month (essentially, push it back one day). Leave all other dates alone.

 

So far, I have deduced the following:

 

= if Date.Day([End Current]) = 1 then 
Table.ReplaceValue(#"Changed Type"
,each [End Current]
,each Date.AddDays([End Current], -1)
,Replacer.ReplaceValue,{"End Current"}) else 
[End Current]

 

But I am receiving the error "Expression.Error: There is an unknown identifier. Did you use the [field] shorthand for a _[field] outside of an 'each' expression?"

 

And I can't trace it.

 

Anybody have an idea about how to resolve?

 

FYI: Date.Day function returns a numeric for the date referenced, and Date.AddDays adds or removes an integer number of days according to the argument given (in this case, -1).

 

What am I missing?

 

THANK YOU! Robot Happy

1 ACCEPTED SOLUTION
FarhanAhmed1984
Resolver III
Resolver III

Can you please try this... Replacer.ReplaceValues may have some issues in conditional replace

 

 

 

#"OutP" =
Table.RenameColumns(
    Table.RemoveColumns(
        Table.AddColumn( #"Changed Type", "NewDate",
        each if Date.Day([End Current]) = 1 then
                    Date.AddDays([End Current], -1) else [End Current]),
         {"End Current"}),{{"NewDate", "End Current"}})

View solution in original post

1 REPLY 1
FarhanAhmed1984
Resolver III
Resolver III

Can you please try this... Replacer.ReplaceValues may have some issues in conditional replace

 

 

 

#"OutP" =
Table.RenameColumns(
    Table.RemoveColumns(
        Table.AddColumn( #"Changed Type", "NewDate",
        each if Date.Day([End Current]) = 1 then
                    Date.AddDays([End Current], -1) else [End Current]),
         {"End Current"}),{{"NewDate", "End Current"}})

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors