Forum Discussion
MTD TODAY
Hola buenos dias
estoy intentando crear una medida que me calcule las ventas MTD hasta hoy
pero me interesa que se vea hasta hoy.
el usuario solo filtra por años y por meses, no por dias, por tanto la formula debe coger la fecha actual (hoy)
por ejemplo: si mira este mes, las ventas serian hasta el 11/03, pero si miran el mes pasado hasta el 28/02
esta tabla está relacionado con una tabla calendario[fecha]
apc_123 ,
LYMTD QTY forced=
var _max = date(year(today())-1,month(today()),day(today()))
return
if(max('Date'[Date])<=_max, CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max), blank())
//OR
//CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)
//TOTALMTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max)
3 Replies
- amitchandak
Super User
apc_123 , if you have selected a date this will take till that date. If you have not selected any date try like
MTD QTY forced=
var _max = today()
return
if(max('Date'[Date])<=_max, calculate(Sum('order'[Qty]),DATESMTD('Date'[Date])), blank())
//or
//calculate(Sum('order'[Qty]),DATESMTD('Date'[Date]),filter('Date','Date'[Date]<=_max))
//calculate(TOTALMTD(Sum('order'[Qty]),'Date'[Date]),filter('Date','Date'[Date]<=_max))- apc_123
Helper I
And if i want calculate the previous year
I think i must calculate the var max_old, for example
max_Previous_Year = date(year(today()-1,month(today(),day(today())
is correct ?- amitchandak
Super User
apc_123 ,
LYMTD QTY forced=
var _max = date(year(today())-1,month(today()),day(today()))
return
if(max('Date'[Date])<=_max, CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max), blank())
//OR
//CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)
//TOTALMTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max)