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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.