Forum Discussion

Creative_tree88's avatar
1 year ago
Solved

Lookup latest date, but dealing with multiple values

Hi - I have the attached data.  The data on left represents the source data (shaded yellow), and the data to the right (shaded all blue) represents the desired result using some form of lookup.

 

I need to basically lookup the corresponding value of the latest date, corresponding to height and weight.  Where there is a blank, I need to use the next available date which has a value and return this value.

 

I also need to show the measure date associated with each value (height and weight) to determine whether the two dates are close enough to consider accurate enough to use.  

 

Tricky one...any ideas?  If possible I want to achieve this result using a calculated column using lookup or a derivative of.

 

Thanks all.  Really appreciate your help as always.

 

Sample Data 

  •  

    Last Valid Weight =
    VAR lastdte =
    CALCULATE (
    MAX ( CustomerWeight[Measure Date] ),
    NOT ( ISBLANK ( CustomerWeight[Weight] ) )
    )
    VAR result =
    CALCULATE (
    MAX ( CustomerWeight[Weight] ),
    CustomerWeight[Measure Date] = lastdte
    )
    RETURN
    IF ( result = 0, "No Height Listed", result )

     

9 Replies

  • vanessafvg's avatar
    vanessafvg
    Icon for Community Champion rankCommunity Champion

    do you want the result at a customer level ie per customerr last height and weight as you didn't include in on your result table

  • vanessafvg's avatar
    vanessafvg
    Icon for Community Champion rankCommunity Champion

    there might be an easier way to do it i filtered only on these results as the dates gave me some issues on copying and pasting but essentially it gives the correct answer

     

    you need to do a dax calculation 

    so get the last valid height

     

    Last Valid Height =
    VAR lastdte =
    CALCULATE (
    MAX ( CustomerWeight[Measure Date] ),
    NOT ( ISBLANK ( CustomerWeight[Height] ) )
    )
    RETURN
    CALCULATE (
    MAX ( CustomerWeight[Height] ),
    CustomerWeight[Measure Date] = lastdte
    )

     

    and for the date 

     

    Last Valid Height Date =
    CALCULATE (
    MAX ( CustomerWeight[Measure Date] ),
    NOT ( ISBLANK ( CustomerWeight[Height] ) )
    )

     

     

     

    see solution attached 

    • Creative_tree88's avatar
      Creative_tree88
      Icon for Helper V rankHelper V

      vanessafvg That looks good.  I'll do some data quality checks tomorrow and, if it's OK with you, get back to you if there are any further issues I find once I've incorporated this into my report.  Many thanks indeed.

      • Creative_tree88's avatar
        Creative_tree88
        Icon for Helper V rankHelper V

        vanessafvg Is there a way of introducing text to each measure, to add to the table in the event of there being no data to return.  For example 'No Height Data' where there is nothing.  Many thanks again.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Thanks for the replies from vanessafvg.

     

    Hi Creative_tree88 ,

     

    You can try to create the following four measures:

    Latest Height = CALCULATE(SUM('Table'[Height]),FILTER(ALLEXCEPT('Table','Table'[Customer No]),'Table'[Measure Date]=[Measure Height Date]))
    Latest Weight = CALCULATE(SUM('Table'[Weight]),FILTER(ALLEXCEPT('Table','Table'[Customer No]),'Table'[Measure Date]=[Measure Weight Date]))
    Measure Height Date = CALCULATE(MAX('Table'[Measure Date]),FILTER(ALLEXCEPT('Table', 'Table'[Customer No]),'Table'[Height]>0))
    Measure Weight Date = CALCULATE(MAX('Table'[Measure Date]),FILTER(ALLEXCEPT('Table', 'Table'[Customer No]),'Table'[Weight]>0))

     

    Result:

     

     

    Best Regards,
    Zhu

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.

  • vanessafvg's avatar
    vanessafvg
    Icon for Community Champion rankCommunity Champion

     

    Last Valid Weight =
    VAR lastdte =
    CALCULATE (
    MAX ( CustomerWeight[Measure Date] ),
    NOT ( ISBLANK ( CustomerWeight[Weight] ) )
    )
    VAR result =
    CALCULATE (
    MAX ( CustomerWeight[Weight] ),
    CustomerWeight[Measure Date] = lastdte
    )
    RETURN
    IF ( result = 0, "No Height Listed", result )