DimCalendario = /* ----------------------------------------------------------------------------------------*/ /* ------- Tabla Calendario desarrollada por Toni Jurado. Julio de 2022 -------------------*/ /* ----------------------------------------------------------------------------------------*/ VAR vHoy = TODAY() VAR vAnyoMinimo = 2022 -- Ajustar por el año de inicio del calendario VAR vAnyoMaximo = 2022 -- Ajustar por el año de finalización del calendario RETURN ADDCOLUMNS( CALENDAR( DATE( vAnyoMinimo, 1, 1 ), DATE( vAnyoMaximo, 12, 31 ) ), -- GENERAMOS CALENDARIO BASE "FechaCompleta", FORMAT( [DATE], "DDDD, DD ""de"" MMMM ""de"" yyyy" ), "idFecha", INT( FORMAT( [DATE], "YYYYMMDD" ) ), "Año", YEAR( [DATE] ), "Mes", MONTH( [DATE] ), -- Se utilizará como orden para las columnas NombreMes y MesCorto "NombreMes", FORMAT( [DATE], "MMMM" ), "MesCorto", FORMAT( [DATE], "MMM" ), "Día", DAY( [DATE] ), "NombreDía", FORMAT( [DATE], "DDDD" ), "OrdenDíaSemana", WEEKDAY( [DATE], 2 ), -- Retorna el día número del día de la semana (1-lunes .. 7-domingo) y servirá para ordenar NombreDía "AñoMes", FORMAT( [DATE], "YYYY-MMM" ), "OrdenAñoMes", INT( FORMAT( [DATE], "YYYYMM" ) ), "Trimestre", QUARTER( [DATE] ), "AñoTrimestre", FORMAT( [DATE], "YYYY-""Trim""Q" ), "OrdenAñoTrimestre", FORMAT( [DATE], "YYYYQ" ), "InicioAño", DATE( YEAR( [DATE] ), 1, 1 ), "FinAño", DATE( YEAR( [DATE] ), 12, 31 ), "InicioTrimestre", DATE( YEAR( [DATE] ), ( QUARTER( [DATE] ) * 3 ) - 2, 1 ), -- Retorna la fecha del primer día del trimestre de la fecha "FinTrimestre", EOMONTH( DATE( YEAR( [DATE] ), QUARTER( [DATE] ) * 3, 1 ), 0 ), -- Retorna la fecha del último día del trimestre de la fecha "InicioMes", DATE( YEAR( [DATE] ), MONTH( [DATE] ), 1 ), "FinMes", EOMONTH( [DATE], 0 ), "NumSemana", "Sem " & WEEKNUM( [DATE] ), "OrdenSemana", WEEKNUM( [DATE] ), "AñoSemana", FORMAT( [DATE], "YYYY ""Sem " & WEEKNUM( [DATE] ) ), "OrdenAñoSemana", INT( FORMAT( [DATE], "YYYY" & WEEKNUM( [DATE] ) ) ), "PrimerDíaSemana", IF( WEEKDAY( [DATE], 2 ) = 1, [DATE], [DATE] - WEEKDAY( [DATE], 3 ) ), "UltimoDíaSemana", IF( WEEKDAY( [DATE], 2 ) = 7, [DATE], [DATE] + 6 - WEEKDAY( [DATE], 3 ) ), "Laboral/FinSemana", IF( WEEKDAY( [DATE], 2 ) <= 5, "Laborable", "FinDeSemana" ), "CuantaLaboral", IF( WEEKDAY( [DATE], 2 ) <= 5, 1, 0 ), "CuantaFinSemana", IF( WEEKDAY( [DATE], 2 ) <= 5, 0, 1 ), "Estación", SWITCH( TRUE(), INT( FORMAT( [DATE], "MMDD" ) ) < 0320, "INVIERNO", INT( FORMAT( [DATE], "MMDD" ) ) < 0621, "PRIMAVERA", INT( FORMAT( [DATE], "MMDD" ) ) < 0921, "VERANO", INT( FORMAT( [DATE], "MMDD" ) ) < 1221, "OTOÑO", "INVIERNO" ), "DíasInicioAño", DATEDIFF( DATE( YEAR( [Date] ), 1, 1 ), [Date], DAY ) + 1, "DiasFinAño", DATEDIFF( [DATE], DATE( YEAR( [DATE] ) + 1, 1, 1 ), DAY ) - 1, "Semestre", IF( MONTH( [DATE] ) <= 6, "Semestre 1", "Semestre 2" ), "AñoSemestre", IF( MONTH( [DATE] ) <= 6, YEAR( [DATE] ) & " Semestre 1", YEAR( [DATE] ) & " Semestre 2" ), "OrdenAñoSemestre", INT( FORMAT( [DATE], "YYYY" ) ) * 10 + IF( MONTH( [DATE] ) <= 6, 1, 2 ), "DesvíoDía", DATEDIFF( vHoy, [DATE], DAY ), "DesvíoMes", DATEDIFF( vHoy, [DATE], MONTH ), "DesvíoTrimestre", DATEDIFF( vHoy, [DATE], QUARTER ), "DesvíoAño", DATEDIFF( vHoy, [DATE], YEAR ) )