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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
ShivaPrasad1
Helper I
Helper I

Dynamic rollback to previous 12 months based on date

Hello Team,

 

I have date column of text format where values will be like 2017.12, 2018.01, 2018.12...I want to create a report for which I need to show last 12 months of data only. How can we achieve this requirement to change the values according to current date dynamically?

 

Ex:

Current Month: Aug 2018

Requied report data: Aug 2017 - Jul 2018 (2017.08 - 2018.07 column)

 

Current Month: Mar 2018

Requied report data: Mar 2017 - Feb 2018 (2017.03 - 2018.02 column)

 

 

Thanks in advance.

 

Regards,

Shiva

1 ACCEPTED SOLUTION

Hi @ShivaPrasad1

 

For current month, you may try below measure:

Measure  =
VAR a =
    DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, 1 )
RETURN
    IF (
        MAX ( 'Table'[YearMonth.No] )
            IN DATESINPERIOD ( 'Table'[YearMonth.No], a, -12, MONTH ),
        1
    )

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-cherch-msft
Microsoft Employee
Microsoft Employee

Hi @ShivaPrasad1

 

You may try to add a column to format the text column to date column as below:

 

YearMonth.No =
DATE ( LEFT ( 'Table'[YearMonth], 4 ), RIGHT ( 'Table'[YearMonth], 2 ), 1 )

1.png

 

Then create a measure as requested. For example:

MonthSelect =
VAR a =
    DATE ( YEAR ( SELECTEDVALUE ( 'Current'[Current Month] ) ), MONTH ( SELECTEDVALUE ( 'Current'[Current Month] ) ) - 1, 1 )
RETURN
    IF (
        MAX ( 'Table'[YearMonth.No] )
            IN DATESINPERIOD ( 'Table'[YearMonth.No], a, -12, MONTH ),
        1
    )

2.png

 

 

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks you @v-cherch-msft

 

But we don't have any filter to select current month. It should be change based on the current date. 

 

Regards,

Shiva

Hi @ShivaPrasad1

 

For current month, you may try below measure:

Measure  =
VAR a =
    DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, 1 )
RETURN
    IF (
        MAX ( 'Table'[YearMonth.No] )
            IN DATESINPERIOD ( 'Table'[YearMonth.No], a, -12, MONTH ),
        1
    )

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

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.