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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Pbiuserr
Post Prodigy
Post Prodigy

Last 12 months by SQLBI problem

Hello,
I've created exactly what's here Show last 6 months but for last year (-13) and it works good, however if I have current month (so today is April) it goes from April 2022 till March 2021, so last 13 months, not 12. If I change to any other period it works good

 

Any idea how to overcome that? I can see that it gets "Ordinal -1" - i dont know what it is, perhaps its that what casues the problem?

 

Current month in slicer:

 

Capture.PNG

Any other month:

Capture2.PNG

2 REPLIES 2
amitchandak
Super User
Super User

@Pbiuserr , Can you share the formula you have used

 

//Date1 is independent Date table, Date is joined with Table
new measure =
var _max = maxx(allselected(Date1),Date1[Date])
var _min = eomonth(_max, -12) +1
return
calculate( sum(Table[Value]), filter('Date', 'Date'[Date] >=_min && 'Date'[Date] <=_max))

 

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

@amitchandak 
hi
alike in video, its calculated group. i know there are other approaches but Ive used the one presented in the clip and If I'd need to reverse it, then it would be too much time consuming so I rely on that

VAR NumOfMonths = -13
VAR ReferenceDate = MAX ( 'Calendar'[Date] )
VAR PreviousDates =
DATESINPERIOD (
'Period prev'[Date],
ReferenceDate,
NumOfMonths,
MONTH
)
VAR Result =
CALCULATE (
SELECTEDMEASURE(),
REMOVEFILTERS ( 'Calendar' ),
KEEPFILTERS ( PreviousDates ),
USERELATIONSHIP ( 'Period prev'[Date], 'Calendar'[Date] )
)
RETURN Result

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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