Forum Discussion

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

Return both the Max and Min value for a date

 


So I have 3 columns in 1 table. The table is Billing and the three columns are Id, Date, Insurance Name.

 

IdDateInsurance Name
1008/15/2018Aetna
1008/16/2018Aetna
1018/18/2018Fidelis
1028/25/2018Fidelis
1028/15/2018Healthfirst
1027/15/2018Healthfirst
1028/10/2018Healthfirst
1038/6/2018Aetna
1038/9/2018Aetna
1038/15/2018Healthfirst
1048/24/2018Fidelis
1048/30/2018Fidelis

 

 

I want to only include the values for the max date and min date. I have alot of values for a specific Id, some have like 6 seven fields and I want to do some basic calculations and so only need two date values, the max and min. For examply the original table will now show only these rows:

IdDateInsurance Namemax or min
1008/15/2018Aetnamin
1008/16/2018Aetnamax
1018/18/2018Fidelismax
1028/25/2018Fidelismax
    
1027/15/2018Healthfirstmin
    
1038/6/2018Aetnamin
    
1038/15/2018Healthfirstmax
1048/24/2018Fidelismin
1048/30/2018Fidelismax
  • Hi saanah2019 

    You may create a measure like below:

    Measure =
    VAR min_date =
        CALCULATE ( MIN ( Table1[Date] ), ALLEXCEPT ( Table1, Table1[Id] ) )
    VAR max_date =
        CALCULATE ( MAX ( Table1[Date] ), ALLEXCEPT ( Table1, Table1[Id] ) )
    RETURN
        IF (
            MAX ( Table1[Date] ) = max_date,
            "max",
            IF ( MAX ( Table1[Date] ) = min_date, "min" )
        )
    

    Regards,

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    What determines if you want to see the min or the max?

    • saanah2019's avatar
      saanah2019
      Icon for Helper II rankHelper II

      Anonymous I want to basically filter on the date, so basically create a new column which willl only show me the min and max dates

      • v-cherch-msft's avatar
        v-cherch-msft
        Icon for Microsoft Employee rankMicrosoft Employee

        Hi saanah2019 

        You may create a measure like below:

        Measure =
        VAR min_date =
            CALCULATE ( MIN ( Table1[Date] ), ALLEXCEPT ( Table1, Table1[Id] ) )
        VAR max_date =
            CALCULATE ( MAX ( Table1[Date] ), ALLEXCEPT ( Table1, Table1[Id] ) )
        RETURN
            IF (
                MAX ( Table1[Date] ) = max_date,
                "max",
                IF ( MAX ( Table1[Date] ) = min_date, "min" )
            )
        

        Regards,