Forum Discussion

Hardy2617's avatar
Hardy2617
New Member
10 months ago
Solved

Power Bi latest Date column

I have multiple date columns, and I need latest date in a column, tried using  MAXX , but still not getting correct date for some rows.  is there any concrete DAX formula do do that?

  • Sorry Hardy2617, I really need new glasses. I missed the part that you have multiple columns to compare 🫣

    Do you need the highest date out of the three columns overall or the highest per row?

    Highest date between the three columns for each row:

    Highest Date per Row = 
    VAR DatesTable =
        FILTER(
            {
                ( [DateID] ),
                ( [Date2] ),
                ( [Date3] )
            },
            [Value] <> BLANK()
        )
    RETURN
    MAXX ( DatesTable, [Value] )

     

    -----------------------

     

    Highest date overall accross all rows:

     

    Highest Date All Columns overall = 
    VAR AllDates =
        UNION(
            SELECTCOLUMNS( 'FactTable', "date", 'FactTable'[DateID] ),
            SELECTCOLUMNS( 'FactTable', "date", 'FactTable'[Date2] ),
            SELECTCOLUMNS( 'FactTable', "date", 'FactTable'[Date3] )
        )
    RETURN
    MAXX( FILTER(AllDates, NOT ISBLANK([date])), [date] )

     

  • Hi Hardy2617 

     

    Try the following:

    Max acrross rows (calc column) = 
    MAXX (
        {
            data[Start Date],
            data[End Date],
            data[Order Date],
            data[Delivery Date],
            data[Payment Date]
        },
        [Value]
    )
    

     

    MEASURES: 
    Max date across columns & rows = 
    CALCULATE (
        MAXX (
            {
                MAX ( data[Delivery Date] ),
                MAX ( data[End Date] ),
                MAX ( data[Payment Date] ),
                MAX ( data[Start Date] )
            },
            [Value]
        ),
        REMOVEFILTERS ( data )
    )
    
    
    Max date across rows = 
    MAXX (
        {
            MAX ( data[Delivery Date] ),
            MAX ( data[End Date] ),
            MAX ( data[Payment Date] ),
            MAX ( data[Start Date] )
        },
        [Value]
    )

     

7 Replies

  • Hi Hardy2617 if you want to add it as a calculated column you can use MAX() to add your highest date as a static value in a separate column:

     

    • Hardy2617's avatar
      Hardy2617
      New Member

      Thank fro your Reply KarinSzilagyi , But I have multiple dates columns its for tracking a shipment and it has multiple dates for multiple location that shipment goes through. how to do it then? I tried using MAXX(), but its still getting worng dates or ealiest date for some rows.

      • KarinSzilagyi's avatar
        KarinSzilagyi
        Icon for Super User rankSuper User

        Sorry Hardy2617, I really need new glasses. I missed the part that you have multiple columns to compare 🫣

        Do you need the highest date out of the three columns overall or the highest per row?

        Highest date between the three columns for each row:

        Highest Date per Row = 
        VAR DatesTable =
            FILTER(
                {
                    ( [DateID] ),
                    ( [Date2] ),
                    ( [Date3] )
                },
                [Value] <> BLANK()
            )
        RETURN
        MAXX ( DatesTable, [Value] )

         

        -----------------------

         

        Highest date overall accross all rows:

         

        Highest Date All Columns overall = 
        VAR AllDates =
            UNION(
                SELECTCOLUMNS( 'FactTable', "date", 'FactTable'[DateID] ),
                SELECTCOLUMNS( 'FactTable', "date", 'FactTable'[Date2] ),
                SELECTCOLUMNS( 'FactTable', "date", 'FactTable'[Date3] )
            )
        RETURN
        MAXX( FILTER(AllDates, NOT ISBLANK([date])), [date] )

         

  • Hi Hardy2617 

     

    Try the following:

    Max acrross rows (calc column) = 
    MAXX (
        {
            data[Start Date],
            data[End Date],
            data[Order Date],
            data[Delivery Date],
            data[Payment Date]
        },
        [Value]
    )
    

     

    MEASURES: 
    Max date across columns & rows = 
    CALCULATE (
        MAXX (
            {
                MAX ( data[Delivery Date] ),
                MAX ( data[End Date] ),
                MAX ( data[Payment Date] ),
                MAX ( data[Start Date] )
            },
            [Value]
        ),
        REMOVEFILTERS ( data )
    )
    
    
    Max date across rows = 
    MAXX (
        {
            MAX ( data[Delivery Date] ),
            MAX ( data[End Date] ),
            MAX ( data[Payment Date] ),
            MAX ( data[Start Date] )
        },
        [Value]
    )

     

  • Hi Hardy2617 

     

    You should always provide some sample data (preferably a PBIX file) and show the desired result.

     

    From your written description it is not posible to know for certain how your data is structured therefore any answer you get is certain to require modification before it works for you.

     

    Regards

     

    Phil