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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
PaulTHR
Frequent Visitor

Create date format to show this month last month etc

Hi - is it possible in Powerquery to create a column alongside a date column that does the following...

Today is 17th May - make record state "This Month"
Previous date say 15th April would need to state "Last Month"
Month before that say 15th March would then say "Last Month +1"

The file is constantly being updated and I need to create measures using "This Month" etc..

I am only going to do this for 6 monthly points anything before will get ingored so easy enought to code it in I guess...

Thanks 🙂


1 ACCEPTED SOLUTION

I have managed to create a flag for "This Month" but need to add a "Last Month" & "Previous Month" & "Previous Month +!" etc etc - just 6 times anything out of date range I can 'Else' out

if Date.StartOfMonth([date]) = Date.StartOfMonth(DateTime.Date(DateTime.LocalNow())) then "This Month" else "Not this month"

View solution in original post

5 REPLIES 5
PaulTHR
Frequent Visitor

Thats did it - thanks very much for your suggestion it worked. Thanks

JamesRobson
Resolver II
Resolver II

Try this, you can jsut repeat the last else if until you get the desiered number of months (I only went to Last Month +1)

 

= Table.AddColumn(#"Changed Type", "MonthCheck", each
if Date.StartOfMonth([Date]) = Date.StartOfMonth(DateTime.Date(DateTime.FixedLocalNow()))
then "This Month"
else if Date.StartOfMonth([Date]) = Date.StartOfMonth(Date.AddMonths(DateTime.Date(DateTime.FixedLocalNow()),1))
then "Next Month"
else if Date.StartOfMonth([Date]) = Date.StartOfMonth(Date.AddMonths(DateTime.Date(DateTime.FixedLocalNow()),-1))
then "Last Month"
else if Date.StartOfMonth([Date]) = Date.StartOfMonth(Date.AddMonths(DateTime.Date(DateTime.FixedLocalNow()),-2))
then "Last Month + 1"
else "Check")

lbendlin
Super User
Super User

Yes, that is possible - as long as you refresh this in import mode frequently (daily)

HI yes it reloads a number of times per day and every day so should be able to use Today()

I have managed to create a flag for "This Month" but need to add a "Last Month" & "Previous Month" & "Previous Month +!" etc etc - just 6 times anything out of date range I can 'Else' out

if Date.StartOfMonth([date]) = Date.StartOfMonth(DateTime.Date(DateTime.LocalNow())) then "This Month" else "Not this month"

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.