Forum Discussion
Bergh
4 years agoHelper II
Date issue
Hi. I have a date column that takes away 9 days. [date] -9, but I would not like to include Saturday and Sunday. Only working days / weekdays.
- 4 years ago
ea_minus_9 = VAR Period = 9 VAR EndDate = TableName[ea] RETURN IF ( NOT ISBLANK ( EndDate ), VAR StartDate = EndDate - 2 * Period VAR DatesPeriod = CALENDAR ( StartDate, EndDate ) VAR DatesAndWDs = ADDCOLUMNS ( DatesPeriod, "@WorkingDay", VAR DayOfWeek = WEEKDAY ( [Date], 2 ) RETURN IF ( DayOfWeek IN { 6, 7 }, "No", "Yes" ) ) VAR WDsOnly = FILTER ( DatesAndWDs, [@WorkingDay] = "Yes" ) VAR TopNTable = TOPN ( Period + 1, WDsOnly, [Date], DESC ) RETURN MINX ( TopNTable, [Date] ) )
tamerj1
4 years agoCommunity Champion
Hi Bergh
Not sure if your talking about a date table. However if you dont have a weekday column you can create one or just store in a variable
Working Day =
VAR DayOfWeek = WEEKDAY( 'Date'[Date], 2)
RETURN
IF ( DayOfWeek In { 6, 7 }, "No", "Yes" )You can then use this calculated column to filter your data
9 Days Ago =
MINX (
TOPN (
9,
FILTER ( 'Date', 'Date'[Date] < EARLIER ( 'Date'[Date] ) && 'Date'[Working Day] = "Yes" ),
'Date'[Date],
DESC
),
'Date'[Date]
)