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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
kinder
New Member

Only show the last 24 months, starting from previous month

Hi Guys,

 

I wan't a measure or column that shows me the last 24 months, from last month.  So that will be March 2017 - March 2019.

 

The data set is simple

 

Sales data table,

Sales Number,

Value,

Date

 

 

Calendar

Year,

Month,

MonthYear

 

Feel free to add any fields in the Calendar to do the last 24 months, starting from previous month.

 

And the financial year starts in June.

 

Thanks

 

Lak

1 ACCEPTED SOLUTION
judspud
Solution Supplier
Solution Supplier

Thanks for this @kinder 

 

Please use this formula;

 

Last 2 Years = if(And('Date'[Date]>=date(year(today()),Month(today())-25,1),'Date'[Date]<=(date(year(today()),month(today()),1)-1)),TRUE(),FALSE())
 
Feel free to simplify this were possible as this is a rough and ready one that provides what you need.
 
You can then apply a report level filter to only display True values
 
Thanks,
George

View solution in original post

6 REPLIES 6
judspud
Solution Supplier
Solution Supplier

Hi @kinder 

 

You can create a calculated column in the calendar table to indicate whether the date is in your specified time period.

An if statement to check whether the date is greater than or equal to last month minus 2 years and less or equal to last month.

 

Then apply a report level filter to only include rows where the new column = True

 

Hope this helps

 

Thanks,

George

 

 

Thanks, but what is the syntax of that if statement.

judspud
Solution Supplier
Solution Supplier

@kinder Please could you share an extract of your Calendar table so i can see the format of each column?

 

Thanks,

George

You can create one from scratch to make it easier.

 

Or

 

Date =
ADDCOLUMNS (
CALENDAR (DATE(2018,1,1), DATE(2022,31,12)),
"DateAsInteger", FORMAT ( [Date],"YYYYDDMM" ),
"Year", YEAR ( [Date] ),
"Monthnumber", FORMAT ( [Date], "MM" ),
"YearMonthnumber", FORMAT ( [Date], "YYYY/MM" ),
"YearMonthShort", FORMAT ( [Date], "YYYY/mmm" ),
"MonthNameShort", FORMAT ( [Date], "mmm" ),
"MonthNameLong", FORMAT ( [Date], "mmmm" ),
"DayOfWeekNumber", WEEKDAY ( [Date] ),
"DayOfWeek", FORMAT ( [Date], "dddd" ),
"DayOfWeekShort", FORMAT ( [Date], "ddd" ),
"Quarter", "Q" & FORMAT ( [Date], "Q" ),
"YearQuarter", FORMAT ( [Date], "YYYY" ) & "/Q" & FORMAT ( [Date], "Q" )
)

judspud
Solution Supplier
Solution Supplier

Thanks for this @kinder 

 

Please use this formula;

 

Last 2 Years = if(And('Date'[Date]>=date(year(today()),Month(today())-25,1),'Date'[Date]<=(date(year(today()),month(today()),1)-1)),TRUE(),FALSE())
 
Feel free to simplify this were possible as this is a rough and ready one that provides what you need.
 
You can then apply a report level filter to only display True values
 
Thanks,
George

That worked a treat. Thanks

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.