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

Mes a mismo mes año anterior

Hola

Estoy configurando una matriz con el Año como columnas, Mes como filas y ventas como valor - por lo que para la fila de julio, puede ver las ventas para 2017-2020. Quiero agregar una columna para el crecimiento año tras año. Tengo estas dos medidas, pero la producción cuando en la matriz no proporciona un número correcto para el crecimiento.

Diferencia de año á suma('Ventas'[Gross])-CALCULATE(sum('Sales'[Gross]),PREVIOUSYEAR('Calendar'[Valor de fecha]))
Año % De cambio á [Diferencia de año]/(CALCULATE(sum('Sales'[Gross]),PREVIOUSYEAR('Calendar'[Date Value])))
No estoy seguro de por qué la medida proporciona números incorrectos. Funciona cuando las filas no están relacionadas con la fecha (es decir, no el mes).
1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hola @astano05 ,

El problema es que utiliza la función DAX incorrecta.

La función PREVIOUSYEAR devuelve todas las fechas del año anterior dada la fecha más reciente en el parámetro de entrada. Por ejemplo, si la fecha más reciente en el argumento dates hace referencia al año 2009, esta función devuelve todas las fechas para el año 2008, hasta el year_end_date especificado.

Debe utilizar la función SAMEPERIODLASTYEAR en lugar de la función PREVIOUSYEAR.

Puede escribir sus medidas de la siguiente manera:

Year Difference =
SUM ( 'Sales'[Gross] )
    - CALCULATE (
        SUM ( 'Sales'[Gross] ),
        SAMEPERIODLASTYEAR ( 'Calendar'[Date Value] )
    )
Year % Change =
IF (
    CALCULATE (
        SUM ( 'Sales'[Gross] ),
        SAMEPERIODLASTYEAR ( 'Calendar'[Date Value] )
    ) <> 0,
    [Year Difference]
        / CALCULATE (
            SUM ( 'Sales'[Gross] ),
            SAMEPERIODLASTYEAR ( 'Calendar'[Date Value] )
        )
)

Estos son los resultados de mi propia prueba:

TEST1.pngTEST2.png

Puede comprobar más detalles en mi archivo .pbix.

Saludos

Icey

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

3 REPLIES 3
Icey
Community Support
Community Support

Hola @astano05 ,

El problema es que utiliza la función DAX incorrecta.

La función PREVIOUSYEAR devuelve todas las fechas del año anterior dada la fecha más reciente en el parámetro de entrada. Por ejemplo, si la fecha más reciente en el argumento dates hace referencia al año 2009, esta función devuelve todas las fechas para el año 2008, hasta el year_end_date especificado.

Debe utilizar la función SAMEPERIODLASTYEAR en lugar de la función PREVIOUSYEAR.

Puede escribir sus medidas de la siguiente manera:

Year Difference =
SUM ( 'Sales'[Gross] )
    - CALCULATE (
        SUM ( 'Sales'[Gross] ),
        SAMEPERIODLASTYEAR ( 'Calendar'[Date Value] )
    )
Year % Change =
IF (
    CALCULATE (
        SUM ( 'Sales'[Gross] ),
        SAMEPERIODLASTYEAR ( 'Calendar'[Date Value] )
    ) <> 0,
    [Year Difference]
        / CALCULATE (
            SUM ( 'Sales'[Gross] ),
            SAMEPERIODLASTYEAR ( 'Calendar'[Date Value] )
        )
)

Estos son los resultados de mi propia prueba:

TEST1.pngTEST2.png

Puede comprobar más detalles en mi archivo .pbix.

Saludos

Icey

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

amitchandak
Super User
Super User

@astano05 , Si usted está buscando YTD, no utilice el año anterior. Te dará un año completo. También si su año fuera no es de enero a dec, usted tiene que dar una fecha de finalización.

referimos a estos ejemplos

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
This year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR('Date'[Date]),"12/31"))
Last year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))
Last year Sales = CALCULATE(SUM(Sales[Sales Amount]),previousyear('Date'[Date],"12/31"))
Last to last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-2,Year),"12/31"))
Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))

Asegúrese de que la tabla de fechas esté marcada como una tabla de fechas y que tenga todas las fechas allí.

https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a

parry2k
Super User
Super User

@astano05 se marca su calendario como tabla de fechas?

Me gustaría elogiossi mi solución ayudara.👉Si puedes pasar tiempo publicando la pregunta, también puedes hacer esfuerzos para dar a Kudos quien haya ayudado a resolver tu problema. ¡Es una muestra de agradecimiento!

Visítenos enhttps://perytus.com, su ventanilla única para proyectos/formación/consulta relacionadas con Power BI.



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.

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.