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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Dimitris_Kats
Helper V
Helper V

Error with DateAdd

Dear members Hello

 

I am calculating the Current Month Sales amount:

CM Sales = CALCULATE(SUM(Sales[Sales]))

Also the Previous Month Sales

PM Sales = CALCULATE(SUM(Sales[Sales]), DATEADD(Time[Month], -1, Month))

 

And last i am checking if there are any changes on sales amount month by month

 

Sales Dif = IF(ISBLANK([CM Sales]), BLANK(),IF(ISBLANK([PM Sales]),blank(), IF([CM Sales] = [PM Sales], BLANK(), [CM Sales] - [PM Sales]))))

 

This measures works well and it gives me the desired results. If there are new products that doesn't have any sales yet i get them as blank rows.

When i am trying though to add a Filter to remove tha BLANK rows (Sales Dif is not BLANK)  i get an error that DATEADD expects a contiguous selection.

I am using a calendar table and the problem is when I select on my slicer months of previous year.

 

Is there any way to fix this?

 

Thank you in advance! 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Dimitris_Kats ,

 

Try to sumx your original measure to get correct result in total.

PM Sales with correct Total = SUMX(VALUES('Time'[Month]),[PM Sales])
Sales Dif with correct Total = SUMX(VALUES('Time'[Month]),[Sales Dif])

Result is as below.

RicoZhou_0-1650615010182.png

 

Best Regards,
Rico Zhou

 

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

7 REPLIES 7
Dimitris_Kats
Helper V
Helper V

So, I used PREVIOUSMONTH with the month column of my calendar table and the PM Sales (PM Sales = CALCULATE(SUM(Sales[Sales]), PREVIOUSMONTH (Time[Month])) works well and i don't get an error when i am changing the time periode on the slicer.

The only problem now is that i get either wrong row total or no row total at all.

Do you know can i fix this?? I am sooooo close!!

Anonymous
Not applicable

Hi @Dimitris_Kats ,

 

Try to sumx your original measure to get correct result in total.

PM Sales with correct Total = SUMX(VALUES('Time'[Month]),[PM Sales])
Sales Dif with correct Total = SUMX(VALUES('Time'[Month]),[Sales Dif])

Result is as below.

RicoZhou_0-1650615010182.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

@Dimitris_Kats 

Sorry just noticed your reply. Would you pleas share a screenshot of you date table?

Dimitris_Kats
Helper V
Helper V

Thank you very much @tamerj1  for your reply.

Unfortunatelly when i use the calendar date I don't get results at all.

I tried to use instead of the DATEADD the PREVIOUSMONTH but i don't get correct results and i don't get results by month.

 

I don't know what is wrong

amitchandak
Super User
Super User

@Dimitris_Kats , You should always use a date table for that

 

PM Sales = CALCULATE(SUM(Sales[Sales]), DATEADD(Date[Date], -1, Month))

 

refer

Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5b...


To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hello @amitchandak  and thank you very much for your reply.

I am using a date table for this measure . I use the month column from the date table wich is formatted as date. 
This is not the problem 🙂

@Dimitris_Kats 

The explanation provided by @amitchandak is correct. DATEADD deals with a column of unique date values. The month column even if formatted as date is not unique. Use the date column with DATEADD or YearMonth Number column and subtract 1

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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