Forum Discussion
DAX Calendar Formula for Dates Between Last 2 Week Ending Periods
- 7 years ago
Hi Anonymous ,
To what I can understand you want to calculate your in two weeks based on the last week day of past week so you need to add the weekday calculation to today try to use the following code:
Calendar = VAR TodayWeekEnding = TODAY () + ( ( 7 - WEEKDAY ( TODAY () ) ) ) RETURN ADDCOLUMNS ( CALENDAR ( DATE ( YEAR ( TODAY () ); 1; 1 ); TODAY () ); "Week Ending"; [Date] + ( ( 7 - WEEKDAY ( [Date] ) ) ); "IsCurrentWeek"; IF ( [Date] <= TODAY (); IF ( [Date] >= TODAY () - ( WEEKDAY ( TODAY () ) - 1 ); 1; 0 ); 0 ); "IsLast14Days"; IF ( [Date] <= TODAY (); IF ( [Date] <= TodayWeekEnding - 7 && [Date] >= TodayWeekEnding - 14; 1; 0 ); 0 ); "IsLast30Days"; IF ( [Date] <= TODAY (); IF ( [Date] >= TODAY () - 29; 1; 0 ); 0 ) )Just adjust the bold part for the 30 and 90 days.
Regards,
MFelix
- Anonymous7 years ago
This was close enough for me to get it to the values I was after, THANK YOU!
The VAR was the key that I wasn't thinkng of. Here is what I changed it to with an example:
Today is 4/24, the last 2 weeks ending values would be 4/7 - 4/20 (2 previous periods of weekening 4/20 and 4/13 which includes the dates of 4/7 - 4/13 and 4/14 - 4/20.Formula:
Calendar = VAR TodayWeekEnding = TODAY () + ( ( 7 - WEEKDAY ( TODAY () ) ) ) RETURN ADDCOLUMNS ( CALENDAR ( DATE ( YEAR ( TODAY () ); 1; 1 ); TODAY () ); "Week Ending"; [Date] + ( ( 7 - WEEKDAY ( [Date] ) ) ); "IsCurrentWeek"; IF ( [Date] <= TODAY (); IF ( [Date] >= TODAY () - ( WEEKDAY ( TODAY () ) - 1 ); 1; 0 ); 0 ); "IsLast14Days"; IF ( [Date] <= TODAY (); IF ( [Date] <= TodayWeekEnding - 7 && [Date] >= TodayWeekEnding - 20; 1; 0 ); 0 ); "IsLast30Days"; IF ( [Date] <= TODAY (); IF ( [Date] >= TODAY () - 29; 1; 0 ); 0 ) )
Hi Anonymous ,
Glad I could help, please mark the correct answer in order to help other as well.
Regards,
MFelix
I am not seeing a option to mark as correct. I only am given the kudos options. Where is the mark as correct option?
- MFelix7 years ago
Super User
You should have 3 buttons kudos, reply and accept as solution.
Regards,
MFelix- Anonymous7 years agoNot applicable
For some reason I do not.
- MFelix7 years ago
Super User
I noticed that you have two nicks one prometheus and prometheus_2 the original post was made in the first nick.
Only the original user o posted, super users and admins can accept answers on a post
.
Why do you have two nicks?
I have accepted the solution for you.
Regards,
MFelix