Forum Discussion
Achieve a KPI with correct values for current and target
Good days to all
I'm trying to visualize a KPI with current values (previous week) and the target the same week of the previous year (-51 weeks)
For the objective everything is perfect, because it is the value of week 48 of last year, but for the current one no, I am bringing the value of week 48 of this year, what I want is that it brings me the total value of both columns it does not matter if it joins weeks.
The main problem I think lies in the form of the trend that we are ordering.
These are the measures:
v_Ventas_Valor_SemanaAnteriorTotal =
VAR FechaHoy = TODAY()
VAR DiaSemanaHoy = WEEKDAY(FechaHoy, 2) -- Lunes = 1, Domingo = 7
VAR FechaInicioSemanaActual = FechaHoy - DiaSemanaHoy + 1 -- Lunes de la semana actual
VAR FechaInicioSemanaAnterior = FechaInicioSemanaActual - 7 -- Lunes de la semana anterior
VAR FechaFinSemanaAnterior = FechaInicioSemanaAnterior + 6 -- Domingo de la semana anterior
-- Calcula el total de ventas para la semana anterior, sin importar el cambio de año
VAR TotalVentasSemanaAnterior =
CALCULATE(
SUM(EncargosAnx[importe]),
EncargosAnx[fecha] >= FechaInicioSemanaAnterior &&
EncargosAnx[fecha] <= FechaFinSemanaAnterior
)
-- Retorna el resultado total de la semana anterior
RETURN
TotalVentasSemanaAnteriorv_Ventas_Valor_AnioPasado_SemanaAnterior =
VAR FechaHoy = TODAY()
VAR DiaSemanaHoy = WEEKDAY(FechaHoy, 2) // Lunes = 1, Domingo = 7
VAR FechaInicioSemanaActual = FechaHoy - DiaSemanaHoy + 1 // Lunes de esta semana
VAR FechaInicioSemanaAnioAnterior = FechaInicioSemanaActual - 365 // Lunes de la misma semana en el año anterior
VAR FechaFinSemanaAnioAnterior = FechaInicioSemanaAnioAnterior + 6 // Domingo de la misma semana en el año anterior
-- Validación de fechas (opcional para depuración)
VAR FechaInicio = FechaInicioSemanaAnioAnterior
VAR FechaFin = FechaFinSemanaAnioAnterior
-- Calcula el total del importe para la semana del año anterior
VAR ResultadoAnioPasadoSemanaAnterior =
CALCULATE(
SUM(EncargosAnx[importe]),
EncargosAnx[fecha] >= FechaInicio &&
EncargosAnx[fecha] <= FechaFin
)
-- Retorna el resultado
RETURN
ResultadoAnioPasadoSemanaAnteriorTo change the trend, if I put annual, it brings me the current one and not the previous year:
Thank you very much for any help in advance
Hi Syndicate_Admin ,
Please try the following Sales Total for the Previous Week DAX measure:
v_Ventas_Valor_SemanaAnteriorTotal = VAR FechaHoy = TODAY() VAR DiaSemanaHoy = WEEKDAY(FechaHoy, 2) -- Monday = 1, Sunday = 7 VAR FechaInicioSemanaAnterior = FechaHoy - DiaSemanaHoy - 6 -- Start of last week VAR FechaFinSemanaAnterior = FechaInicioSemanaAnterior + 6 -- End of last week RETURN CALCULATE( SUM(EncargosAnx[importe]), EncargosAnx[fecha] >= FechaInicioSemanaAnterior && EncargosAnx[fecha] <= FechaFinSemanaAnterior )Sales Total for the Same Week Last Year
v_Ventas_Valor_AnioPasado_SemanaAnterior = VAR FechaHoy = TODAY() VAR DiaSemanaHoy = WEEKDAY(FechaHoy, 2) -- Monday = 1, Sunday = 7 VAR FechaInicioSemanaAnterior = FechaHoy - DiaSemanaHoy - 6 -- Start of last week VAR FechaInicioSemanaAnioAnterior = FechaInicioSemanaAnterior - 365 -- Start of same week last year VAR FechaFinSemanaAnioAnterior = FechaInicioSemanaAnioAnterior + 6 -- End of same week last year RETURN CALCULATE( SUM(EncargosAnx[importe]), EncargosAnx[fecha] >= FechaInicioSemanaAnioAnterior && EncargosAnx[fecha] <= FechaFinSemanaAnioAnterior )If the logic still doesn’t work as expected, please let me know.
3 Replies
- Bibiano_Geraldo
Super User
Hi Syndicate_Admin ,
Please try the following Sales Total for the Previous Week DAX measure:
v_Ventas_Valor_SemanaAnteriorTotal = VAR FechaHoy = TODAY() VAR DiaSemanaHoy = WEEKDAY(FechaHoy, 2) -- Monday = 1, Sunday = 7 VAR FechaInicioSemanaAnterior = FechaHoy - DiaSemanaHoy - 6 -- Start of last week VAR FechaFinSemanaAnterior = FechaInicioSemanaAnterior + 6 -- End of last week RETURN CALCULATE( SUM(EncargosAnx[importe]), EncargosAnx[fecha] >= FechaInicioSemanaAnterior && EncargosAnx[fecha] <= FechaFinSemanaAnterior )Sales Total for the Same Week Last Year
v_Ventas_Valor_AnioPasado_SemanaAnterior = VAR FechaHoy = TODAY() VAR DiaSemanaHoy = WEEKDAY(FechaHoy, 2) -- Monday = 1, Sunday = 7 VAR FechaInicioSemanaAnterior = FechaHoy - DiaSemanaHoy - 6 -- Start of last week VAR FechaInicioSemanaAnioAnterior = FechaInicioSemanaAnterior - 365 -- Start of same week last year VAR FechaFinSemanaAnioAnterior = FechaInicioSemanaAnioAnterior + 6 -- End of same week last year RETURN CALCULATE( SUM(EncargosAnx[importe]), EncargosAnx[fecha] >= FechaInicioSemanaAnioAnterior && EncargosAnx[fecha] <= FechaFinSemanaAnioAnterior )If the logic still doesn’t work as expected, please let me know.
- Syndicate_Admin
Administrator
Thank you very much for the answer.
Everything works perfectly
- Bibiano_Geraldo
Super User