Forum Discussion

Arul's avatar
Arul
Super User
7 years ago
Solved

DAX

What is earlier in DAX language?

  • consider this data

    Label Value
    A 1
    A 2
    B 3
    B 4
    C 4
    C 5

    and then compare this calculated columns

    Column1 = CALCULATE(SUM('Table'[Value]),ALL('Table'), 'Table'[Label]='Table'[Label])
    
    Column2 = 
    CALCULATE(
        SUM('Table'[Value]),
        ALL('Table'), 
        'Table'[Label]=EARLIER('Table'[Label]) --we iterate over Table[Label] comparing it over the evalulation of the column in the filter context outside of CALCULATE
    )
    
    Column3 =
    VAR CurrentLabel = 'Table'[Label] -- evaluated in the unmodified row specific context
    RETURN
    CALCULATE(
        SUM('Table'[Value]),
        ALL('Table'), --changes filter context to the whole table
        'Table'[Label]= CurrentLabel 
    )
    

     

     

3 Replies

    • Arul's avatar
      Arul
      Super User

      Can you please explain me with a real time example?

      • Stachu's avatar
        Stachu
        Community Champion

        consider this data

        Label Value
        A 1
        A 2
        B 3
        B 4
        C 4
        C 5

        and then compare this calculated columns

        Column1 = CALCULATE(SUM('Table'[Value]),ALL('Table'), 'Table'[Label]='Table'[Label])
        
        Column2 = 
        CALCULATE(
            SUM('Table'[Value]),
            ALL('Table'), 
            'Table'[Label]=EARLIER('Table'[Label]) --we iterate over Table[Label] comparing it over the evalulation of the column in the filter context outside of CALCULATE
        )
        
        Column3 =
        VAR CurrentLabel = 'Table'[Label] -- evaluated in the unmodified row specific context
        RETURN
        CALCULATE(
            SUM('Table'[Value]),
            ALL('Table'), --changes filter context to the whole table
            'Table'[Label]= CurrentLabel 
        )