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
DemoFour
Responsive Resident
Responsive Resident

How to show Previous month in date table

Hi folks,

I have a date table and within this I have a column that shows the current month so I can then create a Flag for current month.

Number.ToText(Date.Year(DateTimeZone.SwitchZone(DateTimeZone.FixedLocalNow(),10))) & "-" & Number.ToText(Date.Month(DateTimeZone.SwitchZone(DateTimeZone.FixedLocalNow(),10)))

 

What I need to do is show the previous month as a Flag, as the business process is adding a months total during the first week of the next month. So when I display the data it comes up as May instead of April for date entered, 

 

I will use this column in the date table to then show the outstanding data entities for April not May, as I want to add this column as a visual filter, so that it does not filter the rest of the page.

How can I achieve this is M?

 

I have had a look in the M dictionary (as I am new to M) but i cant quite get the right combination of what I want. 

Any help gratefully received. 

1 ACCEPTED SOLUTION
watkinnc
Super User
Super User

You can add a custom column like so:

 

= Table.AddColumn(PriorStepOrTableName, "Month Flag", each if Date.IsInCurrentMonth([Date]) then "Current Month" else if Date.IsInPreviousMonth([Date]) then "Previous Month" else "All Other Months", type text)

 

You can also use Date.IsInPreviousNMonths to take this as far back as you'd like.

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

View solution in original post

2 REPLIES 2
DemoFour
Responsive Resident
Responsive Resident

Morning @watkinnc 

That's great, the mistake that I made was not to nest the DateIsInPreviousMonth in another IF statement, so that when I was using this function it put the Flag in the current month, I guess it makes sense that you can nest IF functions in M.  

Thanks for your help 🙂 

watkinnc
Super User
Super User

You can add a custom column like so:

 

= Table.AddColumn(PriorStepOrTableName, "Month Flag", each if Date.IsInCurrentMonth([Date]) then "Current Month" else if Date.IsInPreviousMonth([Date]) then "Previous Month" else "All Other Months", type text)

 

You can also use Date.IsInPreviousNMonths to take this as far back as you'd like.

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

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.