Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Associate a max value with the original record

I have a table called "Activity" that I'd like to count IDs by PRODUCT_CODE where the max SEQN record is selected for a given ID. A sample of the data from the Activity table.    ID PRODUCT...
  • v-xuding-msft's avatar
    6 years ago

    Hi Anonymous ,

     

    You could try like this:

    LatestSEQN =
    VAR CurrentID =
        SELECTEDVALUE ( 'Activity'[ID] )
    VAR MAX_SEQ =
        MAXX (
            FILTER ( ALL ( 'Activity' ), Activity[ID] = CurrentID ),
            'Activity'[MaxSeq]
        )
    RETURN
        IF ( MAX ( Activity[MaxSeq] ) = MAX_SEQ, MAX_SEQ, BLANK () )
    
    Count 1 =
    CALCULATE (
        DISTINCTCOUNT ( Activity[ID] ),
        FILTER (
            ALLEXCEPT ( Activity, Activity[PRODUCT_CODE] ),
            Activity[MaxSeq] = [LatestSEQN]
        )
    )
    
    
    Count 2 = COUNTX(Activity,[LatestSEQN])