I build a date table in Power BI with all possible combination of date columns. However, I was wondering if it is possible to write one DAX query that creates all these columns automatically.
How to combine the DAX logic from each individual column together so PowerBI creates all the columns at once.
My last try:
DateTable =
VAR BaseCalendar =
CALENDAR(
FIRSTDATE(column X[Date]),
LASTDATE(column X[Date]))
RETURN
GENERATE(
BaseCalendar,
VAR BaseDate = [Date]
VAR YearDate = YEAR(BaseDate)
VAR MonthNumber = MONTH(BaseDate)
RETURN ROW(
"FullYear", YEAR([Date]),
"ShortYear", VALUE(Right(Year([Date]),2)),
"MonthNumber", MONTH([Date]),
"MonthNumberFull", FORMAT([Date], "MM"),
"MonthFull", FORMAT([Date], "MMMM"),
"MonthAbbr", FORMAT([Date], "MMM"),
"WeekNumber", WEEKNUM([Date]),
"WeekNumberFull", FORMAT(Weeknum([Date]), "00"),
"QuarterFull", "Quarter " & ROUNDDOWN(MONTH([Date])/4,0)+1,
"QuarterNumber", ROUNDDOWN(MONTH([Date])/4,0)+1,
"QuarterAndYear", BaseCalendar[QuarterNumber] & " " & [FullYear],
"YearMonthNum", VALUE(BaseCalendar[FullYear] & BaseCalendar[MonthNumberFull]),
"Quarter", "Q" & ROUNDDOWN(MONTH([Date])/4,0)+1,
"ISODate", BaseCalendar[FullYear] & BaseCalendar[MonthNumberFull] & BaseCalendar[DayOfMonthFull],
"DayOfMonth", DAY(BaseCalendar[Date]),
"DayOfMonthFull", FORMAT(DAY(BaseCalendar[Date]),"00"),
"DayOfWeek", WEEKDAY(BaseCalendar[Date],2),
"DayOfWeekFull", FORMAT(BaseCalendar[Date], "DDDD"),
"DayOfWeekAbbr", FORMAT(BaseCalendar[Date], "DDD"),
"DayOfWeekAbbr", FORMAT(BaseCalendar[Date], "DDD"),
"QuarterAbbr", "Qtr" & ROUNDDOWN(MONTH(BaseCalendar[Date])/4,0)+1,
"MonthAndYearAbbr", BaseCalendar[MonthNumberFull] & " " & BaseCalendar[FullYear],
"QuarterAndYearNum", BaseCalendar[FullYear] & BaseCalendar[QuarterNumber],
"QuarterAndYearNum", BaseCalendar[FullYear] & BaseCalendar[QuarterNumber]
)
)
When I hover over the variables that are underlined in red it always says: Cannot find name: XYZ
I do understand that the code above is not working for several reasons. I am new to this and cannot think of a different approach.
My final goal is that I have a block of code I can copy paste when creating a new table that will automatically create all the columns I created by hand once.
Any Input or help is very much appreciated.
Many thanks in advance, MLU