Forum Discussion
NOT IN function for holidays
- 4 years ago
hashtag_pete How about:
Calendar = GENERATE( CALENDARAUTO(), var YYYY = YEAR( [Date] ) var MMM = MONTH( [Date] ) var Holidays = {DISTINCT(Feiertage[Column2])} return ROW( "Year", YYYY, "Month", FORMAT( [Date] , "mmmm" ), "Month No", MMM, "Weekday", FORMAT( [Date], "dddd"), "Weekday No", WEEKDAY( [Date], 2), "WorkingDay", NOT ( WEEKDAY( [Date], 2) in {6,7} ) && NOT(CONTAINS(Holidays,[Column2],[Date])) ) ) - 4 years ago
hashtag_pete Well, I actually think that this is the better solution (below). I think that it is working because it ends up referencing a column in an actual table, [Column2] because the Holidays variable would have a column name of [Value] and not [Column2]. So probably a bit of luck. However, if you do it this way is better:
Calendar = VAR Holidays = DISTINCT(Feiertage[Column2]) RETURN GENERATE( CALENDARAUTO(), var YYYY = YEAR( [Date] ) var MMM = MONTH( [Date] ) return ROW( "Year", YYYY, "Month", FORMAT( [Date] , "mmmm" ), "Month No", MMM, "Weekday", FORMAT( [Date], "dddd"), "Weekday No", WEEKDAY( [Date], 2), "WorkingDay", NOT ( WEEKDAY( [Date], 2) in {6,7} ) && NOT([Date] in Holidays) ) )
Greg_Deckler not quite sure why it works but it does 😄
I thought that the IN operator is just syntax sugar for contains, but obviously in the background something is working differently. Thanks for pointing that one out
hashtag_pete Well, I actually think that this is the better solution (below). I think that it is working because it ends up referencing a column in an actual table, [Column2] because the Holidays variable would have a column name of [Value] and not [Column2]. So probably a bit of luck. However, if you do it this way is better:
Calendar =
VAR Holidays = DISTINCT(Feiertage[Column2])
RETURN
GENERATE(
CALENDARAUTO(),
var YYYY =
YEAR( [Date] )
var MMM =
MONTH( [Date] )
return
ROW(
"Year", YYYY,
"Month", FORMAT( [Date] , "mmmm" ),
"Month No", MMM,
"Weekday", FORMAT( [Date], "dddd"),
"Weekday No", WEEKDAY( [Date], 2),
"WorkingDay", NOT (
WEEKDAY( [Date], 2) in {6,7}
) && NOT([Date] in Holidays)
)
)