The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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
Solved! Go to Solution.
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
Thank you for your support marcelsmaglhaes
Hi, @pablol1235
Based on your description, I've built this simple dataset below:
First, I have a date table that I don't have a relationship for:
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:
Here are the results:
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.
Thank you for your support marcelsmaglhaes
Hi, @pablol1235
Based on your description, I've built this simple dataset below:
First, I have a date table that I don't have a relationship for:
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:
Here are the results:
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
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
Si funcionó
Muchas gracias
User | Count |
---|---|
79 | |
78 | |
37 | |
33 | |
31 |
User | Count |
---|---|
93 | |
81 | |
59 | |
49 | |
48 |