Forum Discussion
DATEADD not fully working
Hello!
I have a table with 3 columns, Booking Date, Holiday Year, Sales Value.
For example, Holidays in 2023 might be booked in the couple of years before the holiday.
I want to use DATEADD to adjust the booking date by years, but where the number of years is dependent on the Holiday Year.
I created the following formula, which is nearly working:
Adjusted Sales = CALCULATE( [Sales] , DATEADD( [Booking Date] , (MAX('Data'[Holiday Year])-2023), YEAR) )
So Holidays in 2023 have no adjustment. Holidays in 2022 have the booking date moved forward 1 year. Etc, etc.
This is working mainly, but I'm ending up with a table like the below. It is great for Holiday Years from 2020, but before then, its giving me the correct totals but there are no sales in the individual booking dates.
| Holiday year >>> | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 2023 |
| Booking year (below) | |||||||
| 2021 | - | - | - | 7m | 2m | 1m | 5m |
| 2022 | - | - | - | 9m | 4m | 7m | 10m |
| 2023 | - | - | - | 9m | 1m | 3m | 7m |
| TOTAL | 5m | 4m | 10m | 26m | 6m | 11m | 22m |
I've tried replacing the formula as below, as a test for 2019, and it works fine!
Adjusted Sales = CALCULATE( [Sales] , DATEADD( [Booking Date] , -4, YEAR) )
Any idea what could be causing the problem?
Thanks so much!
Justin
1 Reply
- Greg_DecklerCommunity Champion
colverjustin Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882
Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.