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

Fechas YTD inconsistentes con YTD del año anterior

Tengo una variedad de medidas que aprovechan las expresiones DATESYTD, DATESQTD y DATESMTD, pero encuentro que los intervalos de fechas son ligeramente inconsistentes al comparar con el año anterior.

Ejemplo 1:

YTD - DATESYTD(DateTable[Fecha])
Fechas de devolución entre el 1 de enero y el 10 de dición
YTD LY - DATEADD(DATESYTD(DateTable[Date]),-365,DAY)
Fechas de devolución entre Jan 1 - Sep 11
En este ejemplo, no puedo averiguar cómo alinear las fechas, si cambio el número de días, simplemente desplaza el error en una dirección diferente. ¿Hay algo que pueda hacer para que las fechas coincidan?

Ejemplo 2:

QTD - DATESQTD(DateTable[Fecha])
Fechas de devolución entre el 1 de julio y el 10 de julio
QTD LY á DATEADD(DATESQTD(DateTable[Date]),-365,DAY)
Fechas de devolución entre el 2 y el 11 de julio
En este ejemplo, sin embargo, puedo alinear las fechas simplemente cambiando el número de días a -366
1 ACCEPTED SOLUTION

Hey @FrazerPwC ,

Recomiendo leer este artículo, prestar atención a las notas: https://dax.guide/sameperiodlastyear/

Para este reaseon tuve que cambiar la instrucción DAX de dateTable a esto:

DateTable = CALENDAR(
    //MIN(Orders[Date]),MAX(Orders[Date])
    DATE( 2015 , 1 , 1 )
    , DATE( 2020 , 12 , 31 )
    )


Luego creé estas dos medidas:

Tom Current Year 2020-01-01 - 09-10 = 
var _lastdate = DATE( 2020 , 9 , 10 )
var _firstDayOfTheYear = DATE( YEAR(_lastdate) , 1 , 1 )
var theDates = DATESBETWEEN( 'DateTable'[Date] , _firstDayOfTheYear , _lastdate )
return

CALCULATE(
    SUM('Orders'[Sales])
    , FILTER(
        ALL('DateTable')
        , 'DateTable'[Date] in theDates
    )
)

Y el más interesante:

Tom Previous Year 2019-01-01 - 09-10 = 
var _lastdate = DATE( 2020 , 9 , 10 )
var _firstDayOfTheYear = DATE( YEAR(_lastdate) , 1 , 1 )
var theDates = 
    SAMEPERIODLASTYEAR(DATESBETWEEN( 'DateTable'[Date] , _firstDayOfTheYear , _lastdate ))
    

var theStartDate = MINX( theDates , 'DateTable'[Date] )
var theEndDate = MAXX( theDates , 'DateTable'[Date])
var noofday = COUNTROWS( theDates )
var thevalue = 
CALCULATE(
    SUM('Orders'[Sales])
    , FILTER(
        ALL('DateTable')
        , 'DateTable'[Date] in theDates
    )
)
return

"startdate: " & theStartDate
& UNICHAR(10) & "enddate: " & theEndDate
& UNICHAR(10) & "no of days: " & noofday 
& UNICHAR(10) & "value: " & thevalue 

Es simplemente más redactatorio, ya que también uso esto para documentar lo que está pasando.
Sin embargo, todo esto me permite crear esto:
dataplat-00018.png

Con suerte, esto es lo que estás buscando.

saludos

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

15 REPLIES 15

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.