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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
pablol1235
Helper I
Helper I

desde comienzo de año al mes anterior

Estimados como están?

 

Tengo una tabla con una columna fechas y otra ventas

 

Quiero poder seleccionar un mes y que me traiga las ventas desde el 1 de enero al último día del mes anterior

 

Ejemplo

 

Selecciono Diciembre y quiero que me traiga las ventas desde el 1/1/24 al 30/11/24

Si selecciono Setiembre quiero que me traiga desde 01/01/24 al 31/8/24

Si selecciono Mayo 2023 que me traiga las ventas desde 01/01/23 al 30/4/23

 

Muchas gracias

2 ACCEPTED SOLUTIONS
marcelsmaglhaes
Super User
Super User

Hola @pablol1235 

Puedes intentar usar la siguiente medida para calcular las ventas acumuladas desde el 1 de enero hasta el último día del mes anterior a la fecha seleccionada:

Ventas Acumuladas Hasta Mes Anterior =
VAR FechaSeleccionada = MAX('Vendas'[FechaVenta]) -- Obtiene la fecha más reciente del filtro
VAR AñoSeleccionado = YEAR(FechaSeleccionada) -- Obtiene el año de la fecha seleccionada
VAR MesSeleccionado = MONTH(FechaSeleccionada) -- Obtiene el mes de la fecha seleccionada
VAR UltimoDiaMesAnterior = EOMONTH(FechaSeleccionada, -1) -- Último día del mes anterior
VAR PrimerDiaAño = DATE(AñoSeleccionado, 1, 1) -- Primer día del año seleccionado
RETURN
CALCULATE(
SUM('Vendas'[ValorVenta]),
'Vendas'[FechaVenta] >= PrimerDiaAño && 'Vendas'[FechaVenta] <= UltimoDiaMesAnterior
)


Regards,
Marcel Magalhães
Microsoft Power BI Official Partner
MCT | Certified PL-300 Power BI

If I've helped, don't forget to mark my post as a solution!



View solution in original post

Anonymous
Not applicable

Thank you for your support marcelsmaglhaes

Hi, @pablol1235 

Based on your description, I've built this simple dataset below:

vjianpengmsft_0-1737954085485.png

First, I have a date table that I don't have a relationship for:

vjianpengmsft_1-1737954124488.png

Establish the following measure:

Measure = 
VAR _min_seleted_month_days = min('DateTable'[Date]) -1
VAR _selected_year_min_day = MINX(FILTER(ALL(DateTable),'DateTable'[Year] = MIN('DateTable'[Year])),'DateTable'[Date])
RETURN CALCULATE(SUM('Table'[Sales]),DATESBETWEEN('Table'[Date],_selected_year_min_day,_min_seleted_month_days))

Use the year and month of the date table to create two slicers:

vjianpengmsft_2-1737954190002.png

Here are the results:

vjianpengmsft_3-1737954274845.png

vjianpengmsft_4-1737954309868.png

I've provided the PBIX file used this time below.

 

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Thank you for your support marcelsmaglhaes

Hi, @pablol1235 

Based on your description, I've built this simple dataset below:

vjianpengmsft_0-1737954085485.png

First, I have a date table that I don't have a relationship for:

vjianpengmsft_1-1737954124488.png

Establish the following measure:

Measure = 
VAR _min_seleted_month_days = min('DateTable'[Date]) -1
VAR _selected_year_min_day = MINX(FILTER(ALL(DateTable),'DateTable'[Year] = MIN('DateTable'[Year])),'DateTable'[Date])
RETURN CALCULATE(SUM('Table'[Sales]),DATESBETWEEN('Table'[Date],_selected_year_min_day,_min_seleted_month_days))

Use the year and month of the date table to create two slicers:

vjianpengmsft_2-1737954190002.png

Here are the results:

vjianpengmsft_3-1737954274845.png

vjianpengmsft_4-1737954309868.png

I've provided the PBIX file used this time below.

 

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Excelente!!

Muchas gracias

marcelsmaglhaes
Super User
Super User

Hola @pablol1235 

Puedes intentar usar la siguiente medida para calcular las ventas acumuladas desde el 1 de enero hasta el último día del mes anterior a la fecha seleccionada:

Ventas Acumuladas Hasta Mes Anterior =
VAR FechaSeleccionada = MAX('Vendas'[FechaVenta]) -- Obtiene la fecha más reciente del filtro
VAR AñoSeleccionado = YEAR(FechaSeleccionada) -- Obtiene el año de la fecha seleccionada
VAR MesSeleccionado = MONTH(FechaSeleccionada) -- Obtiene el mes de la fecha seleccionada
VAR UltimoDiaMesAnterior = EOMONTH(FechaSeleccionada, -1) -- Último día del mes anterior
VAR PrimerDiaAño = DATE(AñoSeleccionado, 1, 1) -- Primer día del año seleccionado
RETURN
CALCULATE(
SUM('Vendas'[ValorVenta]),
'Vendas'[FechaVenta] >= PrimerDiaAño && 'Vendas'[FechaVenta] <= UltimoDiaMesAnterior
)


Regards,
Marcel Magalhães
Microsoft Power BI Official Partner
MCT | Certified PL-300 Power BI

If I've helped, don't forget to mark my post as a solution!



Si funcionó

Muchas gracias

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.