Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
JellyFishBi
Helper I
Helper I

MTD / LY MTD

Gracias por leer.

Tengo dos medidas:
MTD - TOTALMTD(SUM('4011-Visits'[GrossProd]),'Date'[Date])

MTD LY - CALCULATE([MTD],DATEADD('Date'[Date], -1,YEAR))
Y el resultado:
SnipMTD.JPG
¿Cómo consigo que MTD LY toal se ajuste correctamente? El valor que buscamos es 594.233.
Muchas gracias,
Mike

12 REPLIES 12
v-alq-msft
Community Support
Community Support

Hola, @JellyFishBi

Según su descripción, creé datos para reproducir su escenario. El archivo pbix se adjunta al final.

4011-Visitas:
d1.png

Puede crear medidas como se indica a continuación.

MTD = 
var _maxdate = MAX('4011-Visits'[Date])
var _year = YEAR(_maxdate)
var _month = MONTH(_maxdate)
var _day = DAY(_maxdate)
return
CALCULATE(
    SUM('4011-Visits'[GrossProd]),
    FILTER(
        ALLSELECTED('4011-Visits'),
        '4011-Visits'[Date]>=DATE(_year,_month,1)&&
        '4011-Visits'[Date]<=DATE(_year,_month,_day)
    )
)

MTD LY = 
var _maxdate = MAX('4011-Visits'[Date])
var _year = YEAR(_maxdate)
var _month = MONTH(_maxdate)
var _day = DAY(_maxdate)
return
CALCULATE(
    SUM('4011-Visits'[GrossProd]),
    FILTER(
        ALLSELECTED('4011-Visits'),
        '4011-Visits'[Date]>=DATE(_year-1,_month,1)&&
        '4011-Visits'[Date]<=DATE(_year-1,_month,_day)
    )
)

Resultado:

d2.png

Saludos

Allan

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

Gracias Allan. Parece que tu solución bien pensada salvó el día.

¿Podría ser abel para hacer lo mismo para la semana hasta la fecha del año pasado (WTD LY)? Actualmente tengo WTD como:

WTD ?
Fecha actual del VAR (VAR CurrentDate)
LASTDATE ( 'Fecha'[Fecha] )
Var DayNumberOfWeek ?
SEMANA ( LASTDATE ( 'Fecha'[Fecha] ), 3 )
devolución
CALCULAR (
SUM ( '4011-Visitas'[GrossProd] ),
FECHAS ENTRE LAS FECHAS (
'Fecha'[Fecha],
DATEADD ( CurrentDate, -1 * DayNumberOfWeek, DAY ),
CurrentDate
)
)

@JellyFishBi que probó la solución @jdbuchanan71 publicado. Nunca publicó comentarios sobre esa solución. Creo que deberías probar y decir si funcionó o no.



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.

Ashish_Mathur
Super User
Super User

Hola

¿Funcionan estas medidas?

MTD - SUM('4011-Visits'[GrossProd])

MTD LY - CALCULATE([MTD],SAMEPERIODLASTYEAR('Date'[Date]))

Espero que esto ayude.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Tan extraño. He utilizado estas medidas en el pasado, y he funcionado bien en el pasado. Ejecuto al menos 10 modelos dimilar diferentes con la lógica que ha especificado y hace dos días, la lógica había fallado. Me llevó a preguntarme la integridad de la tabla de fechas. Todo parecía caer en su lugar cuando puse el valor de la tabla de fechas finales en Today(). @Ashish_Mathur En sus viajes, ¿ha experimentado alguna vez sus medidas de repente fallando?

Mike

Hola

¿Ha resuelto su pregunta?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
jdbuchanan71
Super User
Super User

@JellyFishBi

Agregue una columna a su tabla 'Fecha' llamada 'Es pasado'

=DATE[Date] <= TODAY()

A continuación, puede cambiar su PY MTD

MTD LY = 
CALCULATE( [MTD],
    CALCULATETABLE (
        SAMEPERIODLASTYEAR ( DATE[Date] ),
        DATE[Is Past] = TRUE
    )
)

Esto evitará que el calc LY pase la fecha actual, pero en el año anterior.

@jdbuchanan71 gran idea, pero evitaría agregar columna innecesaria, sino más bien obtener la última fecha de transacción y filtrar en eso, lo que sucede si no está mirando el año actual, que viene 2019 vs 2018, esta lógica no funcionará.

Aunque es una solución genial.



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.

@parry2k

Si usted está mirando en 2019 vs 2018 su no va a tener un mes con resultados corrientes parciales, pero completo py reusults aunque. Puede cambiar la comprobación de 'Is Past' para ver say MAX(Sales[Invoice Date]) en su lugar si no desea utilizar TODAY().

Para @parry2k punto, si no desea que la columna 'Es pasado' puede obtener la última fecha de transacción de su tabla de detalles y usarla en un VAR como tal.

MTD LY = 
VAR _LastDate = '4011-Visits'[DateField]
CALCULATE( [MTD],
    CALCULATETABLE (
        SAMEPERIODLASTYEAR ( DATE[Date] ),
        DATE[Date] <= _LastDate
    )
)

¡Gracias por la ayuda!

parry2k
Super User
Super User

@JellyFishBi aplica filtro en la fecha? Total está dando el mes completo de PY.



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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors