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.
Queridos todos,
Tengo una lista de líneas de pedido, y me gustaría calcular la media móvil (12 meses) de pedidos que se han realizado:
Tengo la siguiente tabla:
DateDoc nrMonth
1-1-2020 | 0001 | 1 |
1-1-2020 | 0001 | 1 |
2-1-2020 | 0002 | 1 |
1-2-2020 | 0003 | 2 |
2-2-2020 | 0004 | 2 |
2-2-2020 | 0004 | 2 |
3-2-2020 | 0005 | 2 |
1-3-2020 | 0006 | 3 |
2-3-2020 | 0007 | 3 |
2-3-2020 | 0007 | 3 |
3-3-2020 | 0008 | 3 |
4-3-2020 | 0009 | 3 |
4-3-2020 | 0009 | 3 |
pero de alguna manera la siguiente medida no funciona:
Mes | Distinctcount | Distinctcount últimos doce meses | Media móvil |
1 | 2 | 2 | 2,00 |
2 | 3 | 5 | 2,50 |
3 | 4 | 9 | 3,00 |
Hola, @VictorV
Según su descripción, creé datos para reproducir su escenario.
Mesa:
Calendario:
Calendar = CALENDARAUTO()
Hay una relación de varios a uno entre 'Tabla' y 'Calendario'.
Puede crear una columna calculada y tres medidas como se muestra a continuación.
Calculated column:
Monthnum = MONTH('Calendar'[Date])
Measure:
Distinctcount = DISTINCTCOUNT('Table'[Doc nr])
Distinctcount last 12 months =
IF(
NOT(ISBLANK([Distinctcount])),
CALCULATE(
DISTINCTCOUNT('Table'[Doc nr]),
DATESINPERIOD(
'Calendar'[Date],
LASTDATE('Calendar'[Date]),
-12,
MONTH
)
)
)
Moving average =
var monthnum = SELECTEDVALUE('Calendar'[Monthnum])
var _lastdistinct =
CALCULATE(
DISTINCTCOUNT('Table'[Doc nr]),
FILTER(
ALLSELECTED('Calendar'),
'Calendar'[Monthnum] = monthnum-1
)
)
return
IF(
monthnum = 1,
DIVIDE(
[Distinctcount],
1
),
DIVIDE(
[Distinctcount last 12 months],
_lastdistinct
)
)
Resultado:
Saludos
Allan
Si este post ayuda,entonces por favor considere Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.
@VictorV para cualquier inteligencia de tiempo es una práctica recomendada agregar una tabla de calendario y realizar cálculos a partir de eso. Hay muchos mensajes que muestran que puede agregar dimensiones de calendario/fecha en el modelo.
Me 💖 Kudos 🙂 si mi solución me ayudara. Si puedes pasar tiempo publicando la pregunta, también puedes hacer esfuerzos para darle a Kudos quien haya ayudado a resolver tu problema. ¡Es una muestra de agradecimiento!
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
Gracias, así que en mi ejemplo real im usando una tabla dim de calendario, pero en este ejemplo lo dejé fuera.
con o sin, todavía enfrentando el problema.. supongamos que reemplaza el campo de fecha de la tabla de hechos con la tabla de calendario.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
2 | |
2 | |
2 | |
2 | |
1 |