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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Display previous X period base on user selection

Is there a formula that solve this?

When the user select a period e.i 2021 P13 W4 from slicer, the line chart will shown the selected period value with the 7 last periods value
I've watched some videos about it but of all them uses a specific date colum, our period colum is based on Year + Period + Week (1-4)
These are the periods

EduardoCED_0-1640292105780.png

and line chart

EduardoCED_1-1640292136144.png

 

2 REPLIES 2
Anonymous
Not applicable

Hi @Anonymous ,

You can refer the following links to achieve it.

Display Last N Months & Selected Month using Single Date Dimension in Power BI 

Show previous 6 months of data from single slicer selection

--
--  This calculation item works together with the Previous Date table to show
--  6 months back from the currently selected date in the Date table.
--
'Previous Period'[Previous Period]."Previous 6 Months" =
 
VAR NumOfMonths = -6
VAR ReferenceDate = MAX ( 'Date'[Date] )
VAR PreviousDates =
    DATESINPERIOD (
        'Previous Date'[Date],
        ReferenceDate,
        NumOfMonths,
        MONTH
    )
VAR Result =
    CALCULATE (
        SELECTEDMEASURE (),
        REMOVEFILTERS ( 'Date' ),
        KEEPFILTERS ( PreviousDates ),
        USERELATIONSHIP ( 'Previous Date'[Date], 'Date'[Date] )
    )
RETURN Result

Previous Dynamic Period using DAX in Power BI

If the above ones can't help you, please provide some sample data(exclude sensitive data) and your expected result with backend logic and special examples. Thank you.

Best Regards

amitchandak
Super User
Super User

@Anonymous , if you select a period and want data more than that you need independent period /date table.

 

Assume you have an independent date/period table and one joined. You need have rank on this period to make it work

 

Column in both tables

 

Period Rank = RANKX(all(Period),Period[year period],,ASC,Dense)

 

TI using joined table
This Period = CALCULATE(sum('Table'[Qty]), FILTER(ALL(Period),Period[Period Rank]=max(Period[Period Rank])))
Last Period = CALCULATE(sum('Table'[Qty]), FILTER(ALL(Period),Period[Period Rank]=max(Period[Period Rank])-1))

 

 

This will not work when select 1 and want to display more 

 


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

 

 

Need of an Independent Date Table:https://www.youtube.com/watch?v=44fGGmg9fHI

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

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.

Top Solution Authors