-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathCalendar.dax
50 lines (48 loc) · 2.95 KB
/
Calendar.dax
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Calendar =
VAR _today_date = TODAY() //'Properties'[Today Date]
VAR _fiscal_year = YEAR(EDATE( _today_date, 6))
VAR _fiscal_year_start = DATE ( _fiscal_year - 1, 07, 01)
VAR _fiscal_year_end = DATE ( _fiscal_year, 06, 30)
VAR _result =
ADDCOLUMNS
(
//CALENDARAUTO() //range of dates is calculated automatically based on data in the model
CALENDAR(_fiscal_year_start, _fiscal_year_end)
, "Calendar Year Period End", FORMAT([Date], "yyyy12")
, "Calendar Year Period Start", FORMAT([Date], "yyyy01")
, "Calendar Year Period", FORMAT([Date], "yyyyMM")
, "Calendar Year Quarter Nbr", QUARTER([Date])
, "Calendar Year Quarter", FORMAT([Date], "\C\Yyyyy \Qq")
, "Calendar Year Half", FORMAT([Date], "\F\Yyyyy \H") & ROUNDUP(MONTH([Date]) / 6, 0)
, "Calendar Year", YEAR([Date])
, "Day Name Short", FORMAT([Date], "DDD")
, "Day Name", FORMAT([Date], "DDDD")
, "Day Of Week", WEEKDAY([Date])
, "Day", DAY([Date])
, "Fiscal Year Period End", FORMAT(EDATE([Date], 6), "yyyy12")
, "Fiscal Year Period Start", FORMAT(EDATE([Date], 6), "yyyy01")
, "Fiscal Year Period", FORMAT(EDATE([Date], 6), "yyyyMM")
, "Fiscal Year Quarter Nbr", FORMAT(EDATE([Date], 6), "q")
, "Fiscal Year Quarter", FORMAT(EDATE([Date], 6), "\F\Yyyyy \Qq")
, "Fiscal Year Half", FORMAT(EDATE([Date], 6), "\F\Yyyyy \H") & ROUNDUP(MONTH(EDATE([Date], 6)) / 6, 0)
, "Fiscal Year", YEAR(EDATE([Date], 6))
, "Is Current FY", IF(YEAR(EDATE([Date], 6)) = _fiscal_year, 1, 0)
, "Is Future", IF([Date] > _today_date, 1, 0)
, "Is Past", IF([Date] < _today_date, 1, 0)
, "Is Weekend", IF(WEEKDAY([Date], 1) = 1 || WEEKDAY([Date], 1) = 7, 1, 0)
, "Month End", EOMONTH([Date], 0)
, "Month Name Short", FORMAT([Date], "MMM")
, "Month Name", FORMAT([Date], "MMMM")
, "Month Start", DATE(YEAR([Date]), MONTH([Date]), 1)
, "Month", MONTH([Date])
, "Week Ending", [Date] + 7 - WEEKDAY([Date], 1) // Saturday
, "Week Starting", [Date] - WEEKDAY([Date], 1) + 1 // Sunday
, "Week Day", WEEKDAY([Date], 2)
, "Week of Month", 1 + WEEKNUM([Date]) - WEEKNUM( EOMONTH([Date], -1 ) + 1 )
, "Week of Year", WEEKNUM([Date])
, "Week of Fiscal Year", IF(MONTH([Date]) < 7
, WEEKNUM([Date], 1) + (WEEKNUM(DATE(YEAR([Date]), 7, 1), 1) - 1)
, WEEKNUM([Date], 1) - WEEKNUM(DATE(YEAR([Date]), 7, 1), 1) + 1)
)
RETURN
_result