0% found this document useful (0 votes)
21 views2 pages

Power BI Date Table Script

Uploaded by

gica.duru123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

Power BI Date Table Script

Uploaded by

gica.duru123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

DimCalendar =

GENERATE (
CALENDAR (MIN(Orders[OrderDate]),MAX(Orders[OrderDate])),
VAR currentDay = [Date]
VAR day = DAY( currentDay )
VAR month = FORMAT ( currentDay , "MM" )
VAR monthname = FORMAT ( currentDay , "MMMM" )
VAR shortmonthname = FORMAT ( currentDay , "MMM" )
VAR year = YEAR ( currentDay )
VAR DayofWeek = FORMAT ( [Date], "dddd" )
VAR Quarter = "Q" & FORMAT ( [Date], "Q" )
VAR Week = IF(WEEKNUM([Date],2)>=10,"W" & WEEKNUM([Date],2),"W0" &
WEEKNUM([Date],2))
VAR WeekNumber = WEEKNUM([Date],2)
VAR ISOYear =
IF(AND(WEEKNUM([Date],21) < 5 , WEEKNUM([Date],2) > 50) , year+1 ,
IF(AND(WEEKNUM([Date], 21) > 50 , WEEKNUM([Date], 2) < 5 ), [Date] -
1 , year)
)
VAR ISOWeek = WEEKNUM([Date],21) &"."& ISOYear
VAR YearWeek = year * 100 + WeekNumber
VAR DateKey = FORMAT([Date],"YYYYMMDD")
VAR WeekYear = WeekNumber&"."&year
VAR YearMonthNumber = year * 100 + month
VAR WeekDay = WEEKDAY([Date],2)
VAR CalMonthNumber =
MONTH ( [Date] )
VAR CalDayOfMonth =
DAY ( currentDay )
VAR _CheckLeapYearBefore =
year -
IF ( (CalMonthNumber = 2 && CalDayOfMonth < 29)
|| CalMonthNumber < 2,
1,
0 )
VAR LeapYearsBefore1900 =
INT ( 1899 / 4 )
- INT ( 1899 / 100 )
+ INT ( 1899 / 400 )
VAR LeapYearsBetween =
INT ( _CheckLeapYearBefore / 4 )
- INT ( _CheckLeapYearBefore / 100 )
+ INT ( _CheckLeapYearBefore / 400 )
- LeapYearsBefore1900
VAR Sequential365DayNumber =
INT ( currentDay - LeapYearsBetween )
VAR CurOffSetMonth = DATEDIFF(TODAY(),[Date],MONTH)
--VAR Cuatrimestre =
-- IF(AND(CurOffSetMonth < 1, CurOffSetMonth > -4),"CCuat",
-- IF(AND(CurOffSetMonth < -3, CurOffSetMonth > -8),"LCuat",
-- BLANK()))
--VAR CuatrimestreAnual="C" & ROUNDUP(DIVIDE(MONTH([Date]),4),0) & "." & year
--VAR CuatrimestreNumberAnual = year * 100 + ROUNDUP(DIVIDE(MONTH([Date]),4),0)
--VAR CurOffsetCuatrimestre = (YEAR([Date])-YEAR(TODAY()))*3 +
((ROUNDUP(DIVIDE(MONTH([Date]),4),0))-(ROUNDUP(DIVIDE(MONTH(TODAY()),4),0)))
RETURN ROW (
"day", day,
"Month No", month,
"Month" , monthname,
"Month MMM",shortmonthname,
"MMM Year", UPPER(shortmonthname) &" "& year,
"year", year,
"year/month", CONCATENATE(CONCATENATE(FORMAT(year,"####")," "),shortmonthname),
"Month.Year",FORMAT([Date],"MM.yyyy"),
"DayofWeek",DayofWeek,
"Quarter",Quarter,
--"Cuatrimestre",Cuatrimestre,
-- "Cuatrimestre (Anual)",CuatrimestreAnual,
-- "Cuatrimestre Number",CuatrimestreNumberAnual,
-- "CurOffsetCuatrimestre",CurOffsetCuatrimestre,
"Week",Week,
"ISOWeek",ISOWeek,
"WeekNumber",WeekNumber,
"YearWeek",YearWeek,
"DateKey",DateKey,
"Week No / Year",WeekYear,
"YearMonthNumber",YearMonthNumber,
"Sequential365DayNumber",Sequential365DayNumber,
"Week Day",WeekDay,
"CurOffSetMonth",CurOffSetMonth,
"YTD", IF(AND(YEAR([Date])=YEAR(TODAY()),[Date]<=TODAY()),TRUE(),FALSE()),
"YTD-1",IF(AND(YEAR([Date])=YEAR(TODAY())-1,[Date]<=DATE(YEAR(TODAY())-
1,MONTH(TODAY()),DAY(TODAY()))),TRUE(),FALSE())
))

You might also like