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
j_w
Helper IV
Helper IV

Cómo calcular el total de ventas con el intervalo de fechas modificado en función de los filtros actuales

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.

1 ACCEPTED SOLUTION
v-zhenbw-msft
Community Support
Community Support

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()

howto1.jpg

FY = 
var _FY = if(month([Date])<=3,year([Date])-1,year([Date]))
return
_FY
Star FY = DATE('Date table'[FY],4,1)

howto2.jpg

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
        )
    )

howto3.jpg

howto4.jpg

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.

View solution in original post

6 REPLIES 6
v-zhenbw-msft
Community Support
Community Support

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()

howto1.jpg

FY = 
var _FY = if(month([Date])<=3,year([Date])-1,year([Date]))
return
_FY
Star FY = DATE('Date table'[FY],4,1)

howto2.jpg

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
        )
    )

howto3.jpg

howto4.jpg

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.

amitchandak
Super User
Super User

@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...

amitchandak
Super User
Super User

@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

CNENFRNL
Community Champion
Community Champion

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!

AllisonKennedy
Super User
Super User

¿No está seguro acerca de su ejemplo del caso 2, ¿debería funcionar solo si seleccionan una fecha entre 2019-04-01 y 2020-03-31?

Vea si esto ayuda: https://blog.enterprisedna.co/learn-how-to-calculate-sales-financial-year-to-date/

Es una forma de usar cálculos YTD financieros mediante las funciones de inteligencia de tiempo integradas en Power BI con la fecha de finalización del año especificada. Debe tener una tabla DimDate para que esto funcione correctamente. https://excelwithallison.blogspot.com/2020/04/dimdate-what-why-and-how.html

Please @mention me in your reply if you want a response.

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.

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