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
gluizqueiroz
Resolver I
Resolver I

How to verify if exists a contigous selection? Function 'DATEADD' expects a contiguous selection....

I have the following measure: 

Previous Sales = 
    IF(HASONEVALUE(DateDimension[Year]);
        CALCULATE(SUM(BI_Sales[Value]); DATEADD(DateDimension[DateKey]; -1; YEAR));
        BLANK()
    )

And in my page, I have slicers for month and year, If user selects 2019 and 2018 the measure will work fine, my problem is when the user selects 2019 and 2017 or select just 2019 but 2 months, like January and May, note the months are not sequential.

Is there any way to verify if exists a contiguous selection to treat this case or correct this problem?

I have tried to use SAMEPERIODLASTYEAR.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @gluizqueiroz,

I think you need to create a separate date table and then link your current table to the new date table.
Date table: 

Date = CALENDAR(MIN('DateDimension'[DateKey]),MAX('DateDimension'[DateKey]))

And then you need to redefine this measure as shown below.
Measure: 

Previous Sales =
IF (
    HASONEVALUE ( DateDimension[Year] ),
    CALCULATE (
        SUM ( DateDimension[Value] ),
        FILTER (
            ALL ( 'Date' ),
            YEAR ( 'Date'[Date] )
                = YEAR ( MAX ( 'Date'[Date] ) ) - 1
                && MONTH ( 'Date'[Date] ) = MONTH ( MAX ( 'Date'[Date] ) )
        )
    ),
    BLANK ()
)

Select [Date].Month from the data table as a slicer, the measure still works even if you select two months that are not sequential.

1.png

Best Regards,
Jack Chen

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @gluizqueiroz,

I think you need to create a separate date table and then link your current table to the new date table.
Date table: 

Date = CALENDAR(MIN('DateDimension'[DateKey]),MAX('DateDimension'[DateKey]))

And then you need to redefine this measure as shown below.
Measure: 

Previous Sales =
IF (
    HASONEVALUE ( DateDimension[Year] ),
    CALCULATE (
        SUM ( DateDimension[Value] ),
        FILTER (
            ALL ( 'Date' ),
            YEAR ( 'Date'[Date] )
                = YEAR ( MAX ( 'Date'[Date] ) ) - 1
                && MONTH ( 'Date'[Date] ) = MONTH ( MAX ( 'Date'[Date] ) )
        )
    ),
    BLANK ()
)

Select [Date].Month from the data table as a slicer, the measure still works even if you select two months that are not sequential.

1.png

Best Regards,
Jack Chen

Hey @Anonymous.

Your answer looks good, but I'm not have tried yet, when I try it, I came here to Accept or not your answer as correctly.
I not forget this post.

Thanks.

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