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

Get Fabric certified for FREE! Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

How to create a column showing last 12 months - table with month numbers only, not dates

Hi,

 

I have a table that shows number of worked hours for the company as a total. The numbers are updated manually every month for the previous month (e.g. now in october, the numbers for september were filled in to the excel sheet).

 

I want to create a column that shows "1" if the month is within the last 12 months from todays month, and "0" if not (see illustration below).

 

I have created YearMonth and MonthIndex columns to help me with this, but I am not able to complete the formula to create the "last 12 months" column. Can anyone help me out?

 

Last12Mnts.jpg

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous 

Try a new column like

new column =
var _date = today()
var _max = format(today(), "YYYYMM")
var _min = format(date(year(_date), month(_date)-12,day(_date)), "YYYYMM")
return
if([yearmonth]>=_min && [yearmonth] <= _max ,1,0)

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

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous 

Try a new column like

new column =
var _date = today()
var _max = format(today(), "YYYYMM")
var _min = format(date(year(_date), month(_date)-12,day(_date)), "YYYYMM")
return
if([yearmonth]>=_min && [yearmonth] <= _max ,1,0)

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

Thanks @amitchandak, just what i needed!

Helpful resources

Announcements
Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

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.