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
GD-L
Frequent Visitor

Rolling periods by slicer

Would be able to do manual adjustments in the GL on a weekly basis.

My goal is to use a slicer to select a fiscal year and period (single-select) and a parameter to dictate the number of periods back. I'm using two calendar tables, one for the slicer and the second to render all dates.

 

image.png

 


My goal is to be able to select a year & period and be able to return the N number of months back (e.g. if I select 2022-02, [February], and 3 periods back, my periods would be 02, 01, and 12) but to also be able to look across multiple years for the same periods (e.g. 2022, 2021, 2020 for the periods 02, 01, 12) and be able to return a chart like:

image.png

I get close with:

Sales_Test =
var v_min = [n Months Ago]
var v_max = [SelectedMonth]
return

CALCULATE( sum(Sales[Net Value]),
    REMOVEFILTERS(Calendar1),
    Calendar1[PeriodVal] >= v_min, Calendar1[PeriodVal] <= v_max,
    USERELATIONSHIP(Calendar1[DATE_SQL],Calendar2[DATE_SQL]))


where:

n Months Ago =

var selected_month = DATE(LEFT(SELECTEDVALUE(Calendar1[YearPeriod]),4),right(SELECTEDVALUE(Calendar1[YearPeriod]),2),15)
var nmonths = 'Months Back'[Months Back Value]

var _eom = EOMONTH(selected_month, -nmonths)
var date_build = date(year(_eom),month(_eom),15)

var fisc_per = CALCULATE(min(Calendar2[YearPeriod]),Calendar2[DATE_SQL] = date_build)

return
fisc_per

and

SelectedMonth =
SELECTEDVALUE(Calendar1[YearPeriod])

unfortunately timeintelligence functions do not work due to the custom fiscal calendar.

image.png

1 REPLY 1
MFelix
Super User
Super User

Hi  @GD-L ,

 

Try the following option. http://sqljason.com/2018/03/display-last-n-months-selected-month-using-single-date-dimension-in-powe...


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



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.