Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

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)

 

 

 

 

I appreciate your help

  • Vvelarde's avatar
    Vvelarde
    8 years ago

    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

  • MFelix's avatar
    MFelix
    8 years ago

    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

     

     

    Regards,

    MFelix

8 Replies

  • 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

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi MFelix, thanks for answering

       

      It doesn't work, I shows the following

       

       

       

       

      "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)

       

       

      • MFelix's avatar
        MFelix
        Super User

        Hi Anonymous,

         

        can you share a sample of the PBIX file?

         

        Regards,

        MFelix