Forum Discussion
Calculating Month-To-Date and Week-to-Date
- 9 years ago
Hi Rsanjuan,
I think the formula for month and week won’t work here, and as you concerned, the formula can’t identify which year the month belongs to, also for the week.
For the Previous sales, the formula posted might not be the correct one, see the testing results, the formula used are all copied from the posted ones:
Which I think should be the correct one is the following:
SalesYTD =
TOTALYTD (
[TotalSales],
'Date'[Date]
)
And:
SalesLastYear =
CALCULATE([TotalSales], DATEADD(DATESYTD('Date'[Date]),-1,Year))
Those two formula need a date table to work with.
For month total and Week total, see:
"
Iso MTD :=
IF (
HASONEVALUE ( Dates[ISO Year] )
&& HASONEVALUE (Dates[ISO Month Number] ),
CALCULATE (
SUM ( Sales[Sales Amount] ),
FILTER (
ALL ( Dates ),
Dates[ISO Year] = VALUES ( Dates[ISO Year] )
&& Dates[ISO Month Number] = VALUES ( Dates[ISO Month Number] )
&& Dates[Date] <= MAX ( Dates[Date] )
)
),
BLANK ()
)
Iso WTD :=
IF (
HASONEVALUE ( Dates[ISO Year] )
&& HASONEVALUE (Dates[ISO Week Number] ),
CALCULATE (
SUM ( Sales[Sales Amount] ),
FILTER (
ALL ( Dates ),
Dates[ISO Year] = VALUES ( Dates[ISO Year] )
&& Dates[ISO Week Number] = VALUES ( Dates[ISO Week Number] )
&& Dates[Date] <= MAX ( Dates[Date] )
)
),
BLANK ()
)
"
Check details in the the article below:
Week-Based Time Intelligence in DAX
Before using the formula posted in the article, we need to create a date table containing the following columns:
Year, month and week number in a year.
New table function to create a datetable;
Datatable = calendar(MinDate, MaxDate);
Then add the following columns:
Year = year(Datetable[Date])
Month = month (Datetable[Date])
Weeknum = WeekNum(Datetable[Date])
After that, follow the formula mentioned in the blog to generate the YTD, MTD and WTD function.
If any further help needed, please post back.
Regards
Hello,
I have a situation where I need to calculate the WTD and MTD, QTD and YTD for my sales facts and comparing it with respective previous year numbers. But in my date dimension, the business fiscal year starts on 4th wednesday in March and also 8 of my months end with 28 days and 4 months end with 35 days.
The problem here is that, a perticular month in one fiscal year have different dates in the next year and a perticular fiscal week have different dates in two different years. By which if i calculate with month number and week number then my comparisions are not for the same set of dates.
Can someone please help me on calculating the facts based on the current year dates to the previous year.
Fiscal_Year Fiscal_Year_StartDate Fiscal_Year_EndDate Fiscal_Quarter_Number Fiscal_Quarter_Name Fiscal_Quarter_StartDate Fiscal_Quarter_EndDate Fiscal_Period_Number Fiscal_Period_Name Fiscal_Period_StartDate Fiscal_Period_EndDate
| 2020 | 4/25/2019 12:00:00 AM | 4/22/2020 12:00:00 AM | 4 | Quarter 4 | 1/23/2020 12:00:00 AM | 4/22/2020 12:00:00 AM | 11 | Period 11 | 2/20/2020 12:00:00 AM | 3/18/2020 12:00:00 AM |
| 2020 | 4/25/2019 12:00:00 AM | 4/22/2020 12:00:00 AM | 4 | Quarter 4 | 1/23/2020 12:00:00 AM | 4/22/2020 12:00:00 AM | 11 | Period 11 | 2/20/2020 12:00:00 AM | 3/18/2020 12:00:00 AM |
| 2020 | 4/25/2019 12:00:00 AM | 4/22/2020 12:00:00 AM | 4 | Quarter 4 | 1/23/2020 12:00:00 AM | 4/22/2020 12:00:00 AM | 11 | Period 11 | 2/20/2020 12:00:00 AM | 3/18/2020 12:00:00 AM |
| 2019 | 4/26/2018 12:00:00 AM | 4/24/2019 12:00:00 AM | 4 | Quarter 4 | 1/24/2019 12:00:00 AM | 4/24/2019 12:00:00 AM | 11 | Period 11 | 2/21/2019 12:00:00 AM | 3/20/2019 12:00:00 AM |
| 2019 | 4/26/2018 12:00:00 AM | 4/24/2019 12:00:00 AM | 4 | Quarter 4 | 1/24/2019 12:00:00 AM | 4/24/2019 12:00:00 AM | 11 | Period 11 | 2/21/2019 12:00:00 AM | 3/20/2019 12:00:00 AM |
| 2018 | 4/27/2017 12:00:00 AM | 4/25/2018 12:00:00 AM | 4 | Quarter 4 | 1/25/2018 12:00:00 AM | 4/25/2018 12:00:00 AM | 11 | Period 11 | 2/22/2018 12:00:00 AM | 3/21/2018 12:00:00 AM |
| 2018 | 4/27/2017 12:00:00 AM | 4/25/2018 12:00:00 AM | 4 | Quarter 4 | 1/25/2018 12:00:00 AM | 4/25/2018 12:00:00 AM | 11 | Period 11 | 2/22/2018 12:00:00 AM | 3/21/2018 12:00:00 AM |
the above is an example of how my fiscal year look like.
Thanks in advamce.