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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Jose_Antonio_17
New Member

Calculo con filtro de fechas

Hola a todos.

Os dejo una duda que llevo un tiempo intentando solucionar en Power Bi y no encuentro la manera.
Tengo que ver la variación de una métrica, en este caso usuarios, y tengo como filtro fecha (en meses). He usado la variable de inteligencia de tiempo “cambio mes a mes”, y cuando SOLO selecciono un mes en el filtro de fechas me hace correctamente el cálculo, por ejemplo, selecciono Abril, y el calculo me lo hace “Variación” de Abril vs Marzo.
Mi problema surge cuando selecciono  2 o  3 fechas, os lo cuento con un ejemplo, si selecciono en filtro fechas Abril + Mayo, el cálculo con “cambio mes a mes” me lo hace respecto a Marzo + Abril, y lo que me gustaría es que me lo hiciera respecto a los 2 meses previos a los seleccionados, es decir Febrero + Marzo.

En el caso que tuviera 3 meses seleccionados en el filtro de fechas pues debería de calcularlo respecto a los 3 meses previos a la selección y si tuviera n meses seleccionados pues a los m meses previos a la selección.

Espero lo hayáis entendido.

Muchas gracias por vuestra ayuda.

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

Hi @Jose_Antonio_17 ,

 

Try the following formula:

 

Measure = 
var SelectNum = DISTINCTCOUNT('Calendar'[Year_Month])
return 
    CALCULATE(
        SUM('Table'[value]),
        DATEADD( 'Calendar'[Date], -SelectNum, MONTH )
    )

image.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

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

3 REPLIES 3
v-kkf-msft
Community Support
Community Support

Hi @Jose_Antonio_17 ,

 

Try the following formula:

 

Measure = 
var SelectNum = DISTINCTCOUNT('Calendar'[Year_Month])
return 
    CALCULATE(
        SUM('Table'[value]),
        DATEADD( 'Calendar'[Date], -SelectNum, MONTH )
    )

image.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

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

 

Hi all.
Sorry for answer too late.
This solution is perfect for me, many thanks.

Best regards

amitchandak
Super User
Super User

@Jose_Antonio_17 , Try a measure like

 

same period based on date range
Last Period =
var _max =maxx(date,date[date])
var _min =maxx(date,date[date])
var datediff1 = datediff(_min,_max,day)
var _maxX = _max-datediff1
var _minX = _min -datediff1
return
CALCULATE(SUM(Sales[Sales Amount]),filter(all(date,date[date]<=_maxX &&date[date]>=_minX)))

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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