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
Anonymous
Not applicable

Mostrando una suma de 3 meses atrás para los próximos dos años

Hola chicos,

Estoy atascado y me gustaría pedir ayuda.

Entonces, ¿qué me gustaría hacer? Obtenga la suma de los últimos tres meses y muéstrela para los próximos meses. Es complicado porque me gustaría referirme a la suma de agosto, septiembre y octubre siempre (como estamos en noviembre).

Así que permítanme mostrarles 2 tablas con la fórmula "Valor 3 meses atrás" que se ve así:

Valor de P3M : CALCULATE('Table'[Value],FILTER(ALL('Table'[Date Difference]),'Table'[Diferencia de fecha]>-3 && 'Tabla'[Diferencia de fecha] <0))

Capture.PNG

¿Y qué me gustaría lograr? Permítanme mostrarlo exactamente en Excel.
Q1 es 07/01/2020, 08/01/2020, 09/01/2020
El segundo trimestre es 10,11,12/2020
El tercer trimestre es 01,02,03/2020
El cuarto trimestre es 04,05,06/2020
Capture2.PNG

He probado un montón de cosas y funciona perfectamente mientras toma 3 meses desde el momento en que nos referimos, así que este "Valor 3 meses atrás" está cambiando. Me gustaría que fuera constante a lo largo de los próximos dos años fiscales y se basaría en el mes en el que estamos actualmente.

Espero haberlo explicado de una manera que sea comprensible.
Saludos
Tt

1 ACCEPTED SOLUTION

Hola, @trebor2mng

Puede probar esto en mi archivo de ejemplo anterior:

Measure = 
SUMX (
    SUMMARIZE (
        Table1,
        [Date],
        [Value],
        [Index],
        "threemonthback",
            VAR a =
                SUMX ( FILTER ( ALL ( Table1 ), [Index] = 1 ), [Value] )
            VAR b =
                SUMX ( FILTER ( ALL ( Table1 ), [Index] = 2 ), [Value] )
            VAR c =
                SUMX ( FILTER ( ALL ( Table1 ), [Index] = 3 ), [Value] )
            VAR d = 
                ( b + c + a ) / 3
            var e =
                MAXX(FILTER(ALL(Table1),[Date]=SELECTEDVALUE(Table1[Date])),[Value])
            RETURN
                IF ( SELECTEDVALUE ( Table1[Index] ) < 3, e, d )
    ),
    [threemonthback]
)
Difference = 
SUMX (
    ADDCOLUMNS (
        SUMMARIZE (
            Table1,
            [Date],
            [Value],
            [Index],
            "threemonthback",
            VAR a =
                SUMX ( FILTER ( ALL ( Table1 ), [Index] = 1 ), [Value] )
            VAR b =
                SUMX ( FILTER ( ALL ( Table1 ), [Index] = 2 ), [Value] )
            VAR c =
                SUMX ( FILTER ( ALL ( Table1 ), [Index] = 3 ), [Value] )
            VAR d = 
                ( b + c + a ) / 3
            var e =
                MAXX(FILTER(ALL(Table1),[Date]=SELECTEDVALUE(Table1[Date])),[Value])
            RETURN
                IF ( SELECTEDVALUE ( Table1[Index] ) < 3, e, d )
        ),
        "difference", [threemonthback] - [Value]
    ),
    [difference]
)
Measure 2 = 
SUMX (
    SUMMARIZE (
        Table1,
        [Value],
        [Index],
        "threemonthback",
            VAR a =
                SUMX ( FILTER ( ALL ( Table1 ), [Index] = 1 ), [Value] )
            VAR b =
                SUMX ( FILTER ( ALL ( Table1 ), [Index] = 2 ), [Value] )
            VAR c =
                SUMX ( FILTER ( ALL ( Table1 ), [Index] = 3 ), [Value] )
            return 
                ( b + c + a ) / 3

    ),
    [threemonthback]
)

1.png

Por cierto, desea calcular la suma de 8,9,10, pero definió 7,8,9 como un trimestre. ¿Has considerado esto?

Si no resuelve su problema, por favor no dude en preguntarme.

Saludos

Janey Guo

Si este post ayuda,entonces considere Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Muchas gracias por su ayuda. Funciona según lo esperado.

P.S. Sí, lo he considerado 🙂

Anonymous
Not applicable

Hola

@v-janeyg-msft gracias por su respuesta. Aprecio, sin embargo, este no es el resultado que he esperado.

Esta lógica que puedo lograr mediante una fórmula de ese tipo:

CALCULATE( SUMX('Table',IF(DATEDIFF('Table'[Date],TODAY(),MONTH) <-3 && DATEDIFF('Table'[Date],TODAY(),MONTH) >-1, 'Table'[Value],0))).

Lo que me gustaría mostrar y lo veo complicado es no mover el valor de los últimos 3 meses.

Este es tu pbix:

Capture.PNG

y lo que exactamente me gustaría ver es:

Capture2.PNG

Así que el valor de agosto es 67, septiembre 88 y octubre 77. Nos da un total de 232.

Para la tabla mensual me gustaría que se dividiera por 3 (77.33) y se distribuyería por toda la tabla:

77.33 para noviembre, diciembre de 2021 y así sucesivamente. Siempre consulte los últimos 3 meses y luego calcule una diferencia.

Para la tabla trimestral me gustaría referir siempre a 232 valor para Q2, Q3, Q4.

¡Gracias!

saludos

Tt

Hola, @trebor2mng

Puede probar esto en mi archivo de ejemplo anterior:

Measure = 
SUMX (
    SUMMARIZE (
        Table1,
        [Date],
        [Value],
        [Index],
        "threemonthback",
            VAR a =
                SUMX ( FILTER ( ALL ( Table1 ), [Index] = 1 ), [Value] )
            VAR b =
                SUMX ( FILTER ( ALL ( Table1 ), [Index] = 2 ), [Value] )
            VAR c =
                SUMX ( FILTER ( ALL ( Table1 ), [Index] = 3 ), [Value] )
            VAR d = 
                ( b + c + a ) / 3
            var e =
                MAXX(FILTER(ALL(Table1),[Date]=SELECTEDVALUE(Table1[Date])),[Value])
            RETURN
                IF ( SELECTEDVALUE ( Table1[Index] ) < 3, e, d )
    ),
    [threemonthback]
)
Difference = 
SUMX (
    ADDCOLUMNS (
        SUMMARIZE (
            Table1,
            [Date],
            [Value],
            [Index],
            "threemonthback",
            VAR a =
                SUMX ( FILTER ( ALL ( Table1 ), [Index] = 1 ), [Value] )
            VAR b =
                SUMX ( FILTER ( ALL ( Table1 ), [Index] = 2 ), [Value] )
            VAR c =
                SUMX ( FILTER ( ALL ( Table1 ), [Index] = 3 ), [Value] )
            VAR d = 
                ( b + c + a ) / 3
            var e =
                MAXX(FILTER(ALL(Table1),[Date]=SELECTEDVALUE(Table1[Date])),[Value])
            RETURN
                IF ( SELECTEDVALUE ( Table1[Index] ) < 3, e, d )
        ),
        "difference", [threemonthback] - [Value]
    ),
    [difference]
)
Measure 2 = 
SUMX (
    SUMMARIZE (
        Table1,
        [Value],
        [Index],
        "threemonthback",
            VAR a =
                SUMX ( FILTER ( ALL ( Table1 ), [Index] = 1 ), [Value] )
            VAR b =
                SUMX ( FILTER ( ALL ( Table1 ), [Index] = 2 ), [Value] )
            VAR c =
                SUMX ( FILTER ( ALL ( Table1 ), [Index] = 3 ), [Value] )
            return 
                ( b + c + a ) / 3

    ),
    [threemonthback]
)

1.png

Por cierto, desea calcular la suma de 8,9,10, pero definió 7,8,9 como un trimestre. ¿Has considerado esto?

Si no resuelve su problema, por favor no dude en preguntarme.

Saludos

Janey Guo

Si este post ayuda,entonces considere Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.

v-janeyg-msft
Community Support
Community Support

Hola, @trebor2mng

Es un placer responder por ti.

De acuerdo con su descripción, creo que puede crear una columna de índice en pq primero, luego crear dos medidas para calcular los resultados deseados.

Así:

Value 3 months back = 
SUMX (
    SUMMARIZE (
        Table1,
        [Date],
        [Value],
        [Index],
        "threemonthback",
            VAR a =
                MAXX (
                    FILTER ( ALL ( Table1 ), [Date] = SELECTEDVALUE ( Table1[Date] ) ),
                    [Index]
                )
            VAR aa =
                SUMX ( FILTER ( ALL ( Table1 ), [Index] = a ), [Value] )
            VAR b =
                SUMX ( FILTER ( ALL ( Table1 ), [Index] = a - 1 ), [Value] )
            VAR c =
                SUMX ( FILTER ( ALL ( Table1 ), [Index] = a - 2 ), [Value] )
            VAR d =
                SUMX ( FILTER ( ALL ( Table1 ), [Index] = a - 3 ), [Value] )
            VAR e = ( b + c + d ) / 3
            RETURN
                IF ( SELECTEDVALUE ( Table1[Index] ) < 3, aa, e )
    ),
    [threemonthback]
)
Difference = 
SUMX (
    ADDCOLUMNS (
        SUMMARIZE (
            Table1,
            [Date],
            [Value],
            [Index],
            "threemonthback",
                VAR a =
                    MAXX (
                        FILTER ( ALL ( Table1 ), [Date] = SELECTEDVALUE ( Table1[Date] ) ),
                        [Index]
                    )
                VAR aa =
                    SUMX ( FILTER ( ALL ( Table1 ), [Index] = a ), [Value] )
                VAR b =
                    SUMX ( FILTER ( ALL ( Table1 ), [Index] = a - 1 ), [Value] )
                VAR c =
                    SUMX ( FILTER ( ALL ( Table1 ), [Index] = a - 2 ), [Value] )
                VAR d =
                    SUMX ( FILTER ( ALL ( Table1 ), [Index] = a - 3 ), [Value] )
                VAR e = ( b + c + d ) / 3
                RETURN
                    IF ( SELECTEDVALUE ( Table1[Index] ) < 3, aa, e )
        ),
        "difference", [threemonthback] - [Value]
    ),
    [difference]
)

2.png

Aquí está mi archivo .pbix de ejemplo. Espero que ayude.

Si no resuelve su problema, por favor no dude en preguntarme.

Saludos

Janey Guo

Si este post ayuda,entonces considere Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.

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.