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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Anonymous
Not applicable

Need help in calculating Rolling quarter

Hi Team,

I have a table with fields Year, Quarter and Value. 

pbi_table.PNG

 

My requirement is, I want to add two filters on the report, year and quarter. If the user select year = 2022 and Quarter =Q1 then I need to display a bar graph with axis as selected quarter and previous 3 Quarters i.e, 2022-Q1, 2021-Q4, 2021-Q3, 2021-Q2.  It should change dynamically like...

if year=2021, Quarter= Q3 then Axis = 2021-Q3, 2021-Q2, 2021-Q1, 2020-Q4

if year=2022, Quarter= Q2 then Axis = 2022-Q2, 2022-Q1, 2021-Q4, 2021-Q3....so on

 

Can anyone help me with the formula to calculate last 3 quarters based on filter selection.

 

Thanks

1 ACCEPTED SOLUTION
v-luwang-msft
Community Support
Community Support

HI @Anonymous ,

Pls refer the following steps:

1.create index on base table:

INDEX = RANKX('Table','Table'[Year]&""&RIGHT('Table'[Quarter],1),,ASC,Dense)

2.create another table ,the same as base table:

Table 2 = 'Table'

vluwangmsft_0-1648453722313.png

3.create the the following measure:

TEST1 = CALCULATE(MAX('Table 2'[INDEX]),ALLSELECTED('Table 2'))
TEST2 = CALCULATE(MAX('Table 2'[INDEX])-3,ALLSELECTED('Table 2'))
TEST3 = IF(MAX('Table'[INDEX])>='Table 2'[TEST2]&&MAX('Table'[INDEX])<='Table'[TEST1],1,0)

create visual:

vluwangmsft_1-1648454236549.pngvluwangmsft_2-1648454244535.pngvluwangmsft_3-1648454250405.png

 

You could download my pbix file to learn details.

 

 

 

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


Best Regards

Lucien

View solution in original post

2 REPLIES 2
v-luwang-msft
Community Support
Community Support

HI @Anonymous ,

Pls refer the following steps:

1.create index on base table:

INDEX = RANKX('Table','Table'[Year]&""&RIGHT('Table'[Quarter],1),,ASC,Dense)

2.create another table ,the same as base table:

Table 2 = 'Table'

vluwangmsft_0-1648453722313.png

3.create the the following measure:

TEST1 = CALCULATE(MAX('Table 2'[INDEX]),ALLSELECTED('Table 2'))
TEST2 = CALCULATE(MAX('Table 2'[INDEX])-3,ALLSELECTED('Table 2'))
TEST3 = IF(MAX('Table'[INDEX])>='Table 2'[TEST2]&&MAX('Table'[INDEX])<='Table'[TEST1],1,0)

create visual:

vluwangmsft_1-1648454236549.pngvluwangmsft_2-1648454244535.pngvluwangmsft_3-1648454250405.png

 

You could download my pbix file to learn details.

 

 

 

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


Best Regards

Lucien

amitchandak
Super User
Super User

@Anonymous , if select one Qtr and want to display more than one then you need independent date table 

 

example

 

//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))

 

 

if you just want data of 4 qtr , 12 month

Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-12,MONTH))

 

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

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.