Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Syndicate_Admin
Administrator
Administrator

Uso de DATEADD() y filtrado cruzado

¡Hola a todos!

tenemos 2 conjuntos de datos simples + Calendario:

StenX_0-1638562540526.png

nuestra pantalla:

StenX_1-1638562689446.png

Nuestros pasos:

1. elija Productos en la cortadora Prod o déjelo sin seleccionar
2. mes de elección en el mes de la rebanadora (uno o más)
3. Medida [back_month] - contiene el número de meses seleccionados

back_month = (DATEDIFF(MIN('calendar'[Date]),MAX('calendar'[Date]),MONTH)+1)*-1

4. Medida [count_filter] - contiene el número total de filas filtradas en la tabla txt para los meses seleccionados (punto 2) y Productos (punto 1)

5. El problema en el [count_back].

Medida [count_back] - debe contener el número total de filas filtradas en la tabla txt para [back_month] hace meses.

count_back = 
VAR back_month = (DATEDIFF(MIN('calendar'[Date]),MAX('calendar'[Date]),MONTH)+1)*-1
VAR count_back=CALCULATE([count_filter],DATEADD('calendar'[Date],back_month,MONTH),ALL())
RETURN count_back

Puede ver los intervalos de fecha esperados para filtrar [count_back] en Medidas [date_backFr] y [date_backLs]

date_backFr = FIRSTDATE(DATEADD('calendar'[Date],[back_month],MONTH))
date_backLs = LASTDATE(DATEADD('calendar'[Date],[back_month],MONTH))

Por ejemplo
si elegimos el intervalo Mes: (2021-03) & (2021-04), entonces en la Medida [count_back] debemos calcular el número de filas en txt para los intervalos meses anteriores (-2 meses) => (2021-01) & (2021-02)

si elegimos el intervalo Mes: (2021-03), entonces en la Medida [count_back] debemos calcular el número de filas en txt para el intervalo mes anterior (-1 mes) => (2021-02)


En este momento, la medida [count_back] funciona correctamente solo si no usamos el filtro Prod.

Si activamos el filtro Propuct, entonces todo se rompe ((
¿Cómo usar el filtrado adicional de Prod en este caso?

Archivo PBIX: http://ftp.kantartns.ru/download/637ycdxjeb216eym2vw72b13q0jf73/tt.zip

Saludos

1 ACCEPTED SOLUTION

¡Estaba modificando mi fórmula (usando PARALLELPERIOD) y funcionó!

Nprev = 
VAR monthBack = (DATEDIFF(MIN('rsp'[date]),MAX('rsp'[date]),MONTH)+1)*-1
VAR xStart = STARTOFMONTH(PARALLELPERIOD(rsp[date],monthBack,MONTH))
VAR xEnd = ENDOFMONTH(PARALLELPERIOD(rsp[date],monthBack,MONTH))
VAR cntx = CALCULATE(COUNTROWS(txt),FILTER(ALL(rsp[date],rsp[month]),rsp[date]>=xStart && rsp[date]<=xEnd))

RETURN cntx

View solution in original post

3 REPLIES 3
Syndicate_Admin
Administrator
Administrator

@StenX , Prueba como

mismo período basado en el intervalo de fechas
Último período =
var _max =maxx(fecha,fecha[fecha])
var _min =maxx(fecha,fecha[fecha])
var datediff1 = datediff(_min,_max,día)
var _maxX = _max-datediff1
var _minX = _min -datediff1
devolución
CALCULATE(SUM(Sales[Sales Amount]),filter(all(date),date[date]<=_maxX &&date[date]>=_minX)))

¡Gracias por su rápida respuesta!
Mis disculpas por la demora en la respuesta. Nuestra oficina estaba cerrada durante el fin de semana ((

Apliqué su idea para calcular un desplazamiento del mes (s) completo (s).

count_MonthBack = 
VAR xDiffMonthBack = (DATEDIFF(MIN('calendar'[Date]),MAX('calendar'[Date]),MONTH)+1)*-1
VAR xStartBack = STARTOFMONTH(DATEADD('calendar'[Date],xDiffMonthBack,MONTH))
VAR xEndBack = ENDOFMONTH(DATEADD('calendar'[Date],xDiffMonthBack,MONTH))
VAR xCountBack=CALCULATE([cnt],FILTER(all(rsp),rsp[date]>=xStartBack && rsp[date]<=xEndBack))
RETURN xCountBack


Desafortunadamente, no pude hacerlo. Si usamos la cortadora Prod, todo se rompe.
Quizás el problema está en el DATEADD(). ¿Cómo se puede arreglar esto para las métricas mensuales?

Para comprobar:

Si seleccionamos el mes 2021-04, entonces la fecha de la semana debe filtrarse por 01.03.2021-31.03.2021 (un mes)

Si seleccionamos el mes 2021-04&2021-03, entonces la fecha de la semana debe filtrarse por 01.01.2021-28.02.2021 (dos meses)

Saludos

¡Estaba modificando mi fórmula (usando PARALLELPERIOD) y funcionó!

Nprev = 
VAR monthBack = (DATEDIFF(MIN('rsp'[date]),MAX('rsp'[date]),MONTH)+1)*-1
VAR xStart = STARTOFMONTH(PARALLELPERIOD(rsp[date],monthBack,MONTH))
VAR xEnd = ENDOFMONTH(PARALLELPERIOD(rsp[date],monthBack,MONTH))
VAR cntx = CALCULATE(COUNTROWS(txt),FILTER(ALL(rsp[date],rsp[month]),rsp[date]>=xStart && rsp[date]<=xEnd))

RETURN cntx

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.