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
Anonymous
Not applicable

How to Compare two date fields?

I want to compare two date fields or set a value in the "Distancia" field when is showing the oldest date field ("Fecha").

 

I have this:

'Registro Diario' is a table.

A column called "Fecha" and a measure called "Prueba"; "Fecha" comes from a excel file and "Prueba" is calculated as follows

 

Prueba=CALCULATE ( MIN ( 'Registro Diario'[Fecha] ); ALLSELECTED ( 'Registro Diario' ) )

 

The Distancia field is calculated as follows:

 

Distancia (KM)  = IF('Registro Diario'[Fecha]='Registro Diario'[Prueba];0;1)

 

soporte4.png

 

 

 

I appreciate your help

2 ACCEPTED SOLUTIONS

@Anonymous

 

Hi, instead of using a calculated column you need to use a measure

 

D2 =
IF ( MIN ( 'Registro Diario'[Fecha] ) = [Prueba]; 0; 1 )

Regards

 

Victor




Lima - Peru

View solution in original post

Hi @Anonymous,

 

Looking at your PBIX file this as to be change to a measure as I refered in my first post and as @Vvelarde also indicates in his response, if you do that it will give you 0 for the first record and 1 for all the others

 

pozo.png

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

8 REPLIES 8
MFelix
Super User
Super User

Hi @Anonymous,

 

Is Distancia KM a measure or a column?

 

Try to change it to this measure:

 

Distancia (KM)  = IF(MAX('Registro Diario'[Fecha])=[Prueba];0;1)

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Hi @MFelix, thanks for answering

 

It doesn't work, I shows the following

 

Soporte5.png

 

 

 

"Distancia (KM)" is a column of type "Whole number" and format "Decimal Number", "Fecha" is a column of type "Date" and format (d/MM/yyyy), "Prueba" is a measure without type and format (d/MM/yyyy)

 

 

Hi @Anonymous,

 

can you share a sample of the PBIX file?

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Hi @Anonymous,

 

Looking at your PBIX file this as to be change to a measure as I refered in my first post and as @Vvelarde also indicates in his response, if you do that it will give you 0 for the first record and 1 for all the others

 

pozo.png

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Hi @MFelix and @Vvelarde

 

I apologize because I said something wrong, in fact the distance field that I have as a column is because I need to perform the following calculation

 

Distancia (KM)= var Lat1='Registro Diario'[Latitud - Distancia] * 3,1415 / 180
var Lat2 = 'Registro Diario'[Latitud - Distancia.Anterior] * 3,1415 / 180
var Lon1 = 'Registro Diario'[Longitud - Distancia] * 3,1415 / 180
var Lon2 = 'Registro Diario'[Longitud - Distancia.Anterior] * 3,1415 / 180
var valor = Cos( Lat1 ) * Cos( Lat2 ) * Cos( Lon2 - Lon1 ) + Sin( Lat1 ) * Sin( Lat2 )
return IF(valor<0,99999999999999999999;IF('Registro Diario'[Fecha]=CALCULATE ( MIN ( 'Registro Diario'[Fecha] ); ALLSELECTED ( 'Registro Diario' ) );0;6378*ACOS(valor));0)

 

When I try to pass it as a measure this columns weren't recognized

 

'Registro Diario'[Longitud - Distancia.Anterior]

'Registro Diario'[Longitud - Distancia]

'Registro Diario'[Latitud - Distancia.Anterior]

'Registro Diario'[Latitud - Distancia]

 

 

I apologize for the lack of information

 

 

 

Hi @Anonymous,

 

Try to use a MAX or MIN function on those columns to make context on them.

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



@Anonymous

 

Hi, instead of using a calculated column you need to use a measure

 

D2 =
IF ( MIN ( 'Registro Diario'[Fecha] ) = [Prueba]; 0; 1 )

Regards

 

Victor




Lima - Peru

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.