Forum Discussion

saanah2019's avatar
saanah2019
Icon for Helper II rankHelper II
7 years ago
Solved

Find the min and max date

Hi i have a very basic question that I am stuck on.

I have 2 columns from the same table.
Customer Date

Customer    Date
1                 2/2/2018
2                2/6/2018
3                 2/9/2018

so I just want to create a column or measure which will look at each date and then say if it is the min or max date

Customer       Date           Status
1                    2/2/2018       Min
2                   2/6/2018
3                   2/9/2018         Max

  • Hi saanah2019 

    You may create a column like below:

    Column =
    IF (
        'Table'[Date] = MAX ( 'Table'[Date] ),
        "MAX",
        IF ( 'Table'[Date] = MIN ( 'Table'[Date] ), "MIN", BLANK () )
    )
    

    Regards,

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    I ran into this same issue earlier today! I was able to find two solutions which I believe might work for you.  I've included the code and link to the other post below. The first solution is through a calculated column and the second is via a measure. 

     

     

    Is Latest Row Filter = 
    VAR LatestDate = MAXX(FILTER('Table1','Table1'[Type] = EARLIER('Table1'[Type])),'Table1'[Date])
    RETURN IF('Table1'[Date]=LatestDate,1,0)

     

    Measure =
    VAR LatestDate =
        CALCULATE ( MAX ( 'Table1'[Date] ), ALL ( 'table1' ) )
    RETURN
        IF ( MIN ( 'Table1'[Date] ) = LatestDate, 1, 0 )

     

    https://community.powerbi.com/t5/Desktop/Show-only-data-from-the-latest-date/m-p/443987#M205215

     

    Hope these help. 

    • saanah2019's avatar
      saanah2019
      Icon for Helper II rankHelper II
      Anonymous 
      Hey I am not sure why I am not getting the right answer. What am I doign wrong here?
       
      Is Latest Row Filter =
      VAR LatestDate = MAXX(FILTER(Billing,Billing[Bill Date] = EARLIER(Billing[Bill Date)),Billing[Bill Date)
      RETURN IF(Billing[Bill Date=LatestDate,1,0))))
       
      Max =
      VAR LatestDate =
      CALCULATE ( MAX ( Billing[Bill Date] ), ALL ( Billing ) )
      RETURN
      IF ( MIN ( Billing[Bill Date] ) = LatestDate, 1, 0 )
      • v-cherch-msft's avatar
        v-cherch-msft
        Icon for Microsoft Employee rankMicrosoft Employee

        Hi saanah2019 

        You may create a column like below:

        Column =
        IF (
            'Table'[Date] = MAX ( 'Table'[Date] ),
            "MAX",
            IF ( 'Table'[Date] = MIN ( 'Table'[Date] ), "MIN", BLANK () )
        )
        

        Regards,