Forum Discussion

jagorny's avatar
jagorny
Regular Visitor
9 years ago
Solved

Iterating calculations over a table with a max value per group prior to a given date

I've been trying to combine multiple patterns to make this work but I can't get the nesting order right for the tables/results that I want.   I have a table with a1c values that are collected on a ...
  • v-jiascu-msft's avatar
    v-jiascu-msft
    9 years ago

    Hi jagorny,

     

    1. We need two measures to get the latest "value" and "obs_date".

     

    LatestDate =
    MAX ( 'Table1'[obs_date] )
    RespectiveValue =
    VAR latestdate = MAX ( 'table1'[obs_date] )
    RETURN
        CALCULATE ( MAX ( 'Table1'[value] ), 'Table1'[obs_date] = latestdate )

     

     

     

     

     

     

     

     

     

     

    2. Maybe you could try this:

     

    avg =
    VAR maxdate =
        MAX ( 'DimCalendar'[Date] )
    RETURN
        CALCULATE (
            AVERAGEX (
                SUMMARIZE (
                    Table1,
                    'Table1'[person_nbr],
                    "LDate", MAX ( 'Table1'[obs_date] ),
                    "RValue", [RespectiveValue]
                ),
                [RValue]
            ),
            FILTER ( ALL ( DimCalendar ), DimCalendar[Date] <= maxdate )
        )

     

     

     

     

     

     

     

     

     

     

    Best Regards!

    Dale