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

No me deja restar dos fechas

Buenas.

Estoy intentando restar dos fechas, pero no puedo, ya que al crear la medida no me muestra los campos  fecha de la tabla que necesito, mi medida seria :

diferencia = DATEDIFF(    Dcontratos[DESDE]:,  Dcontratos[HASTA],  DAY)

 

En la siguiente captura se puede ver como tengo definido las fechas:

 

fecha2.png

Formato

fecha3.png

 

al crear la medida no me aparece el campo DESDE:

fecha4.png

Estructura y representación

 

fechas1.png

Que falla?

Muchas gracias.

1 ACCEPTED SOLUTION

@Syndicate_Admin No, me refiero a algo como esto:

diff_measure=var startDate=MIN([SINCE:])

var endDate=MAX([HASTA:])

return DATEDIFF(startDate,endDate,DAY)

Variables startDate y endDate se pueden definir de cualquier otra manera. Pero usando variables no necesitas la función DATEDIFF para restar dos fechas, simplemente puedes restar esas variables:

diff_measure=var startDate=MIN([SINCE:])

var endDate=MAX([HASTA:])

return endDate-startDate

View solution in original post

10 REPLIES 10
Syndicate_Admin
Administrator
Administrator

@Syndicate_Admin En la función DATEDIFF tienes que usar fechas de un solo valor en lugar de columnas de fecha. Utilice la variable para definir las fechas de inicio/finalización y, a continuación, utilí sus usos en la función.

Buenas te refieres a esto:

 

fecha5.png

 

Es que lo pongo asi, pero sigue sin dejarme.

@Syndicate_Admin No, me refiero a algo como esto:

diff_measure=var startDate=MIN([SINCE:])

var endDate=MAX([HASTA:])

return DATEDIFF(startDate,endDate,DAY)

Variables startDate y endDate se pueden definir de cualquier otra manera. Pero usando variables no necesitas la función DATEDIFF para restar dos fechas, simplemente puedes restar esas variables:

diff_measure=var startDate=MIN([SINCE:])

var endDate=MAX([HASTA:])

return endDate-startDate

Hola mi problema es al elegir el formato del dato de la medida. No me deja elegir más que fechas. No números ¿me podéis ayudar?

apalomov_0-1660124917737.png

 

Resuelto con Convert (Date, Integer)

OK, me alegro.

Has probado a cambiar el tipo de dato a numero, desde Power Query?

Muchas gracias, me ha funcionado, finalmente he usado el today en Star para calcular a dia de hoy.

Un saludo

@Syndicate_Admin Entonces puedes aceptar mi respuesta como una solución)

Ya esta aceptada.

Un saludo

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.