cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Syndicate_Admin
Administrator
Administrator

No se puede calcular DATEDIFF con la función Max

Hola a todos

Soy bastante nuevo en power bi, así que me gustaría recibir ayuda en esto.

Estoy intentando calcular la diferencia de mes entre la fecha máxima y la fecha seleccionada

Probé 2 métodos diferentes:

Método 1 usando today() y funcionó bien

datediff = DATEDIFF(SELECTEDVALUE(DATOS[fecha].[fecha]),Hoy(),MES)
Sin embargo, cuando intenté utilizar la función Max reemplazando la función Today(), mi resultado volvió a 0
datediff2 = DATEDIFF(SELECTEDVALUE(DATOS[fecha].[fecha]),Máximo(DATOS[fecha].[Fecha]),MES)
¿Alguien sabe por qué mi max() no devuelve la fecha máxima de la tabla?
gracias de antemano!
2 ACCEPTED SOLUTIONS
Syndicate_Admin
Administrator
Administrator

@darlingling520 ,

Puedes probar esto: -

datediff2 = 
var max_date = calculate(max(DATA[date]),ALL(DATA[date]))
return DATEDIFF(SELECTEDVALUE(DATA[date]),max_date,MONTH)

BR

Samarth

View solution in original post

Syndicate_Admin
Administrator
Administrator

De acuerdo, ya lo descubrí yo mismo, para usar la función max

necesito usar maxdate= calculate(max(data[date]),all(data)); Por lo tanto, la fecha máxima será fija y, por lo tanto, puedo usarla para calcular la fecha

View solution in original post

3 REPLIES 3
Syndicate_Admin
Administrator
Administrator

De acuerdo, ya lo descubrí yo mismo, para usar la función max

necesito usar maxdate= calculate(max(data[date]),all(data)); Por lo tanto, la fecha máxima será fija y, por lo tanto, puedo usarla para calcular la fecha

Syndicate_Admin
Administrator
Administrator

@darlingling520 ,

Puedes probar esto: -

datediff2 = 
var max_date = calculate(max(DATA[date]),ALL(DATA[date]))
return DATEDIFF(SELECTEDVALUE(DATA[date]),max_date,MONTH)

BR

Samarth

muchas gracias!!

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors