Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
El informe tiene una tabla Sales con campos Fecha, Producto, Importe$, también tienen dos filtros, Fecha y Producto que coinciden con los campos del mismo nombre.
La fecha de finalización del ejercicio es el 31 de marzo.
¿Cómo escribir una medida para calcular el importe total del año hasta la fecha$ basado en los dos filtros actuales?
Por ejemplo:
Caso 1
Si el usuario seleccionó Intervalo de filtro de fecha de 2020-09-01 a 2020-07-14,
entonces el monto total del año hasta la fecha$ será de 2020-04-01 a 2020-07-14.
Caso 2
Si el usuario seleccionó Intervalo de filtro de fecha de 2020-02-01 a 2020-08-31, con el filtro Producto Product01 seleccionado
entonces el monto total del año hasta la fecha$ será de 2019-04-01 a 2020-08-31 para Product01.
Solved! Go to Solution.
Hola @j_w ,
Podemos crear una tabla de fechas FY que ahora tenga relación con la tabla Sales y una medida para satisfacer sus requisitos.
1. Cree una tabla de fechas y agregue dos columnas.
Date table = CALENDARAUTO()
FY =
var _FY = if(month([Date])<=3,year([Date])-1,year([Date]))
return
_FY
Star FY = DATE('Date table'[FY],4,1)
2. Luego podemos crear una medida y usar la tabla Fecha [Fecha] para ser una segmentación de datos.
Measure =
VAR _min_date =
MIN ( 'Date table'[Date] )
VAR _max_date =
MAX ( 'Date table'[Date] )
VAR _currentFYmonth =
CALCULATE (
MAX ( 'Date table'[Star FY] ),
FILTER ( 'Date table', 'Date table'[Date] = _min_date )
)
VAR _result_date =
IF (
_min_date > _currentFYmonth,
_currentFYmonth,
DATE ( YEAR ( _currentFYmonth ) - 1, MONTH ( _currentFYmonth ), 1 )
)
RETURN
CALCULATE (
SUM ( 'Table'[amount] ),
FILTER (
ALLSELECTED ( 'Table' ),
'Table'[Date] >= _result_date
&& 'Table'[Date] <= _max_date
)
)
Si no cumple con sus requisitos, ¿podría mostrar el resultado esperado exacto basado en la tabla que hemos compartido?
Saludos
Equipo de apoyo a la comunidad _ zhenbw
Si este post ayuda,entonces considere Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.
BTW, pbix como adjunto.
Hola @j_w ,
Podemos crear una tabla de fechas FY que ahora tenga relación con la tabla Sales y una medida para satisfacer sus requisitos.
1. Cree una tabla de fechas y agregue dos columnas.
Date table = CALENDARAUTO()
FY =
var _FY = if(month([Date])<=3,year([Date])-1,year([Date]))
return
_FY
Star FY = DATE('Date table'[FY],4,1)
2. Luego podemos crear una medida y usar la tabla Fecha [Fecha] para ser una segmentación de datos.
Measure =
VAR _min_date =
MIN ( 'Date table'[Date] )
VAR _max_date =
MAX ( 'Date table'[Date] )
VAR _currentFYmonth =
CALCULATE (
MAX ( 'Date table'[Star FY] ),
FILTER ( 'Date table', 'Date table'[Date] = _min_date )
)
VAR _result_date =
IF (
_min_date > _currentFYmonth,
_currentFYmonth,
DATE ( YEAR ( _currentFYmonth ) - 1, MONTH ( _currentFYmonth ), 1 )
)
RETURN
CALCULATE (
SUM ( 'Table'[amount] ),
FILTER (
ALLSELECTED ( 'Table' ),
'Table'[Date] >= _result_date
&& 'Table'[Date] <= _max_date
)
)
Si no cumple con sus requisitos, ¿podría mostrar el resultado esperado exacto basado en la tabla que hemos compartido?
Saludos
Equipo de apoyo a la comunidad _ zhenbw
Si este post ayuda,entonces considere Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.
BTW, pbix como adjunto.
@j_w ,
Puede utilizar el inicio del año con la fecha de finalización del año indicada en función. O puede comenzar el año desde su tabla . Utilice la tabla de fechas cuando necesite fechas continuas para este
Medidas ?
var _min á minx(allselected(Date),startofyear([Date[Date],"3/31")) //or use start of year from calendar from calendar
var _max á maxx(allselected(Date),[Date[Date])
devolución
calculate([measure], filter(all(Date), Date[DAte]<-_max && Date[DAte]>-_min))
FY de su elección - https://community.powerbi.com/t5/Community-Blog/Creating-Financial-Calendar-Decoding-Date-and-Calend...
@j_w ,
Inténtalo como
Medidas ?
var _min á minx(allselected(Date),startofyear([Date[Date],"3/31")) // take start of you date table
var _max á maxx(allselected(Date),[Date[Date])
devolución
calculate([measure], filter(all(Date), Date[DAte]<-_max && Date[DAte]>-_min))
Asegúrese de utilizar una tabla de fechas con fecha continua
Hola, @j_w, puede asignar una fecha específica como year_end_date en TOTALYTD func, diga "3/31" para su caso,
TOTALYTD(<expression>,<dates>[,<filter>][,<year_end_date>])
Documento oficial para más detalles,
https://docs.microsoft.com/en-us/dax/totalytd-function-dax
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
Copying DAX from this post? Click here for a hack to quickly replace it with your own table names
Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C
I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com
@AllisonKennedy He añadido alguna explicación:
En el caso 2, dado que el rango de filtro de fecha seleccionado por el usuario cubre dos ejercicios, por lo que el año hasta la fecha también debe cubrir dos ejercicios 2019-04-01 a la fecha máxima del intervalo de fechas seleccionado por el usuario 2020-08-31.