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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.