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! Request now

Reply
EugenioProlog
Helper I
Helper I

Metric should skip months according to Data Slicer

I have this report where I show total sales per month, and the growth % from previous month.

EugenioProlog_0-1743703817225.png

 

As you can see, I have all months on my data slicer. If I hide a month, the calculation still considers the previous month, even if it is hidden. So for example, if I select 2023-01 and 2023-03, it calculates my 2023-03 Growth % based on my 2023-02 month, even if it is hidden.

I want it to calculate based on the previous visible month. So, for example, if I select 2023-01 and 2023-03, the Growth % metric should be calculated considering 2023-01, not 2023-02. 

Here is my metric:

Sales Growth % Monthly =
VAR CurrentSales = [TotalSales]
VAR PreviousSales =
    CALCULATE(
        [TotalSales],
        DATEADD(dim_calendar[dt_date], -1, MONTH) -- Ajuste para o nível de tempo desejado
    )
RETURN
    IF(NOT ISBLANK(PreviousSales),
       DIVIDE(CurrentSales - PreviousSales, PreviousSales, 0),
       BLANK()
    )
 
1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @EugenioProlog 

You can use OFFSET for this.

Here is an example of how you could update the measure (PBIX attached):

Sales Growth % Monthly (Visible Months) = 
VAR CurrentSales = [TotalSales]
VAR VisibleMonths =
    CALCULATETABLE (
        VALUES ( dim_calendar[Year-Month] ),
        ALLSELECTED ( dim_calendar )
    )
VAR PreviousSales =
    CALCULATE (
        [TotalSales],
        OFFSET ( -1, VisibleMonths ),
        REMOVEFILTERS ( dim_calendar )
    )
RETURN
    IF (
        NOT ISBLANK ( PreviousSales ),
        DIVIDE ( CurrentSales - PreviousSales, PreviousSales, 0 ),
        BLANK ( )
    )

Note that dim_calendar[Year-Month] could be replaced with any column of the same granularity that sorts correctly, e.g. "Start of Month".

 

Does this work for you?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

PBI file attached.

Hope this helps.

Ashish_Mathur_0-1743768184886.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
OwenAuger
Super User
Super User

Hi @EugenioProlog 

You can use OFFSET for this.

Here is an example of how you could update the measure (PBIX attached):

Sales Growth % Monthly (Visible Months) = 
VAR CurrentSales = [TotalSales]
VAR VisibleMonths =
    CALCULATETABLE (
        VALUES ( dim_calendar[Year-Month] ),
        ALLSELECTED ( dim_calendar )
    )
VAR PreviousSales =
    CALCULATE (
        [TotalSales],
        OFFSET ( -1, VisibleMonths ),
        REMOVEFILTERS ( dim_calendar )
    )
RETURN
    IF (
        NOT ISBLANK ( PreviousSales ),
        DIVIDE ( CurrentSales - PreviousSales, PreviousSales, 0 ),
        BLANK ( )
    )

Note that dim_calendar[Year-Month] could be replaced with any column of the same granularity that sorts correctly, e.g. "Start of Month".

 

Does this work for you?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

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!

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
Top Kudoed Authors