Forum Discussion

AP_83's avatar
AP_83
Regular Visitor
4 years ago
Solved

iterate between dates in same column

  This is sample records from a table, which has data for 2 tasks coulmn name is number for that.   1. For each task i have to find the most recent startTime and get the Group for that. IE. fo...
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi AP_83 ,

     

    Please create following measures:

    Last =
    VAR _maxDate =
        MAXX (
            FILTER ( ALL ( 'Table' ), [Number] = MAX ( 'Table'[Number] ) ),
            [StartTime]
        )
    RETURN
        CALCULATE (
            MAX ( 'Table'[Group] ),
            FILTER (
                ALL ( 'Table' ),
                [Number] = MAX ( 'Table'[Number] )
                    && [StartTime] = _maxDate
            )
        )
    
    Last_Group = IF(MAX('Table'[Group]) =[Last],[Last])
    Last_StartTime = IF(MAX('Table'[Group]) =[Last],MAX('Table'[StartTime]))
    Entire Task =
    VAR _min =
        MINX (
            FILTER ( ALL ( 'Table' ), [Number] = MAX ( 'Table'[Number] ) ),
            [Last_StartTime]
        )
    VAR _max =
        MAXX (
            FILTER ( ALL ( 'Table' ), [Number] = MAX ( 'Table'[Number] ) ),
            [Last_StartTime]
        )
    RETURN
        IF (
            MAX ( 'Table'[StartTime] ) >= _min
                && MAX ( 'Table'[StartTime] ) <= _max,
            IF (
                MAX ( 'Table'[AG_Type] ) = "Primary Assignment"
                    && SELECTEDVALUE ( 'Table'[myVendor] ) = TRUE (),
                "Auto",
                "Non-Auto"
            ),
            BLANK ()
        )
    

    Output:

    Best Regards,
    Eyelyn Qin
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.