Forum Discussion
Problems with dates in visuals
- Anonymous8 years ago
You should use a Calendar table. That normalizes the date data. The Date pulled into the Visuals is from the Calendar Table.
Connect the Calendar table to the primary Data Tables. The Data tables should not be connected to each other (most mlikely will not connect). the Calendar table is the common link in the case of using dates.
That will not clean up bad date data.
Here is the code for a Calendar Table I use (change the name in the front to your chosen name but don't use a DAX command name:
Dates_INV = GENERATE (
CALENDAR( DATE( YEAR( TODAY() ) - 3, MONTH( TODAY() ), DAY( TODAY()) ), TODAY()),
VAR startOfWeek = 2 // Where 1 is Sunday so this returns Monday as Week Start
VAR currentDay = [Date]
VAR days = DAY( currentDay )
VAR months = MONTH ( currentDay )
VAR years = YEAR ( currentDay )
VAR nowYear = YEAR( TODAY() )
VAR nowMonth = MONTH( TODAY() )
VAR dayIndex = DATEDIFF( currentDay, TODAY(), DAY) * -1
VAR todayNum = WEEKDAY( TODAY() )
VAR weekIndex = INT( ROUNDDOWN( ( dayIndex + -1 * IF( todayNum + startOfWeek <= 6, todayNum + startOfWeek, todayNum + startOfWeek - 7 )) / 7, 0 ) )
RETURN ROW (
"day", days,
"month", months,
"MonthNameShort", FORMAT ( months, "mmm" ),
"MonthNameLong", FORMAT ( months, "mmmm" ),
"year", years,
"day index", dayIndex,
"week index", weekIndex,
"month index", INT( (years - nowYear ) * 12 + months - nowMonth ),
"year index", INT( years - nowYear )
)
))
You should use a Calendar table. That normalizes the date data. The Date pulled into the Visuals is from the Calendar Table.
Connect the Calendar table to the primary Data Tables. The Data tables should not be connected to each other (most mlikely will not connect). the Calendar table is the common link in the case of using dates.
That will not clean up bad date data.
Here is the code for a Calendar Table I use (change the name in the front to your chosen name but don't use a DAX command name:
Dates_INV = GENERATE (
CALENDAR( DATE( YEAR( TODAY() ) - 3, MONTH( TODAY() ), DAY( TODAY()) ), TODAY()),
VAR startOfWeek = 2 // Where 1 is Sunday so this returns Monday as Week Start
VAR currentDay = [Date]
VAR days = DAY( currentDay )
VAR months = MONTH ( currentDay )
VAR years = YEAR ( currentDay )
VAR nowYear = YEAR( TODAY() )
VAR nowMonth = MONTH( TODAY() )
VAR dayIndex = DATEDIFF( currentDay, TODAY(), DAY) * -1
VAR todayNum = WEEKDAY( TODAY() )
VAR weekIndex = INT( ROUNDDOWN( ( dayIndex + -1 * IF( todayNum + startOfWeek <= 6, todayNum + startOfWeek, todayNum + startOfWeek - 7 )) / 7, 0 ) )
RETURN ROW (
"day", days,
"month", months,
"MonthNameShort", FORMAT ( months, "mmm" ),
"MonthNameLong", FORMAT ( months, "mmmm" ),
"year", years,
"day index", dayIndex,
"week index", weekIndex,
"month index", INT( (years - nowYear ) * 12 + months - nowMonth ),
"year index", INT( years - nowYear )
)
))
OH. When connecting, the Cross Filter dicection is Single and the arrow in the graphical schema should flow from the Calendar table (the table with one point) to the data tables with multiple points (multiple dates).