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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Anonymous
Not applicable

Issue with using DATEADD

Hello everyone,

 

I have some issues with the DATEADD function when selecting certain filters on the dashboard for calculating the number of YTD sales for a selected year. 

 

Number of Sales YTD = CALCULATE(
                                                DISTINCTCOUNT('Sales'[Sales ID]),
                                                DATESYTD('Sales'[Sales Date]))

Number of Sales YTD Comparison = CALCULATE(
                                                                  [Number of Sales YTD],
                                                                   DATEADD(
                                                                                'Sales'[Sales Date],
                                                                                -(YEAR(TODAY())-'Selected Year'[Parameter Value]),
                                                                                 year))

This works perfect for any selected year. However, when I filter down to a specific category by 'clicking' it on the page, I get an card error message that says "DATEADD expects a contiguous selection when the date column is not unique, has gaps or it contains time portion. 

I noticed when I replace DATEADD with PARALLELPERIOD, this seems to solve the problem (I can filter down to categories with no error with the card message) but instead of providing the YTD sales for the selected year, I get the full year sales for the selected year. I.e. if I had selected 2019, the [Number of Sales YTD Comparison] would show the number of sales for 2019, rather than the number of sales YTD for 2019. 
 
Any tips would be appreciated 🙂
1 ACCEPTED SOLUTION
VahidDM
Super User
Super User

HI   @Anonymous

 

Number of Sales YTD Comparison =
VAR _SD = 'Selected Year'[Parameter Value]
VAR _T =
    TODAY()
VAR _TSD =
    DATE( _SD, MONTH( _T ), DAY( _T ) )
RETURN
    CALCULATE(
        DISTINCTCOUNT( 'Sales'[Sales ID] ),
        FILTER(
            ALL( 'Sales' ),
            'Sales'[Sales Date] >= DATE( _SD, 1, 1 )
                && 'Sales'[Sales Date] <= _TSD
        )
    )

 

It'd would be great to add a date table to your model and use that, for adding a date table please check this link: https://www.vahiddm.com/post/creating-calendar-table-with-3-steps

 


Appreciate your Kudos!!
LinkedIn: www.linkedin.com/in/vahid-dm/

 

 

View solution in original post

2 REPLIES 2
VahidDM
Super User
Super User

HI   @Anonymous

 

Number of Sales YTD Comparison =
VAR _SD = 'Selected Year'[Parameter Value]
VAR _T =
    TODAY()
VAR _TSD =
    DATE( _SD, MONTH( _T ), DAY( _T ) )
RETURN
    CALCULATE(
        DISTINCTCOUNT( 'Sales'[Sales ID] ),
        FILTER(
            ALL( 'Sales' ),
            'Sales'[Sales Date] >= DATE( _SD, 1, 1 )
                && 'Sales'[Sales Date] <= _TSD
        )
    )

 

It'd would be great to add a date table to your model and use that, for adding a date table please check this link: https://www.vahiddm.com/post/creating-calendar-table-with-3-steps

 


Appreciate your Kudos!!
LinkedIn: www.linkedin.com/in/vahid-dm/

 

 

wdx223_Daniel
Super User
Super User

Time Intelligence Functions need a real date table with full dates.

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.