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
VV24
Helper III
Helper III

Promedio rodante en el recuento distinto de doc nr

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-202000011
1-1-202000011
2-1-202000021
1-2-202000032
2-2-202000042
2-2-202000042
3-2-202000052
1-3-202000063
2-3-202000073
2-3-202000073
3-3-202000083
4-3-202000093
4-3-202000093

pero de alguna manera la siguiente medida no funciona:

Promedio de 12 meses ?
CALCULATE(DISTINCTCOUNT('Table'[Doc nr]);DATESINPERIOD('Table'[Date]; LASTDATE('Table'[Date]);-12; MES))
Traté de contar el número distintivo de órdenes en los últimos doce meses. esto me da sólo el número distintivo de órdenes en ese mes específico.
los resultados solicitados se encuentran en las dos últimas columnas de la tabla siguiente
MesDistinctcountDistinctcount últimos doce mesesMedia móvil
1222,00
2352,50
3493,00
3 REPLIES 3
v-alq-msft
Community Support
Community Support

Hola, @VictorV

Según su descripción, creé datos para reproducir su escenario.

Mesa:

c1.png

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:

c2.png

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.

parry2k
Super User
Super User

@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.

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.