Forum Discussion

mclarin's avatar
mclarin
Regular Visitor
6 years ago
Solved

Find earliest date across multiple columns

Any ideas for code to return the earliest date across multiple columns? My table has at least five date columns, I need to return the earliest date per row.

  • Hi mclarin ,  I am assuming this is a calculated column. Let me know if this works, as I did it free hand.
    Let me know if you have any questions.

    If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
    Nathaniel

    Calculated column =
    VAR _earlycol1 = table[col1]
    VAR _earlycol2 = table[col2]
    VAR _earlycol3 = table[col3]
    VAR _earlycol4 = table[col4]
    VAR _calc1 =
        IF ( _earlycol1 < _earlycol2, _earlycol1, _earlycol2 )
    VAR _calc2 =
        IF ( calc1 < _earlycol3, _calc1, earlycol3 )
    VAR _calc3 =
        IF ( _calc2 < _earlycol4, _calc2, _earlycol4 )
    RETURN
        _calc3



10 Replies

  • Nathaniel_C's avatar
    Nathaniel_C
    Community Champion

    Hi mclarin ,  I am assuming this is a calculated column. Let me know if this works, as I did it free hand.
    Let me know if you have any questions.

    If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
    Nathaniel

    Calculated column =
    VAR _earlycol1 = table[col1]
    VAR _earlycol2 = table[col2]
    VAR _earlycol3 = table[col3]
    VAR _earlycol4 = table[col4]
    VAR _calc1 =
        IF ( _earlycol1 < _earlycol2, _earlycol1, _earlycol2 )
    VAR _calc2 =
        IF ( calc1 < _earlycol3, _calc1, earlycol3 )
    VAR _calc3 =
        IF ( _calc2 < _earlycol4, _calc2, _earlycol4 )
    RETURN
        _calc3



    • alya1's avatar
      alya1
      Helper V

      Hello, thank you for your solution! May I ask if you have a solution for another column that shows the corresponding earliest dates column header please? 

      • Nathaniel_C's avatar
        Nathaniel_C
        Community Champion

        Hi alya1 ,

        This question focused on each row. You asked for earliest date column header. What are looking for? It is also helpful if can either include your data, or a picture of your issue.

         

        Thank you,

         

        Nathaniel

    • mclarin's avatar
      mclarin
      Regular Visitor

      Thank you Nathaniel_C . This worked great. Since most of the columns were blank, I also performed a check for that, but otherwise, this solved it.

    • Anonymous's avatar
      Anonymous
      Not applicable

      You Can Also Try This One :

      Earliest date =
      VAR D1 = min(table[Date1])
      VAR D2= min(table[Date2])
      VAR D3= min(table[Date3])
      VAR D4= min(table[Date4])
      return
      min(D1,D2,D3,D4)