Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Error in my code?

Hey!

 

Can anyone see what gets wrong with my DAX formula?

 

I write following: 

 
NewRunLoad =
 
VAR minIndx =
      CALCULATE (
           MAX ( Data[Index] ),
                 ALLEXCEPT ( Data, Data[Device] ),
                         Data[Index] > EARLIER (Data[Index] )
 )
 
RETURN
 
IF (
ISBLANK ( minIndx ),
BLANK (),
Data[TimeLoaded_LC]
         - CALCULATE (
             SUM ( Data[TimeLoaded_LC] ),
                          Data[Index] = minIndx,
              ALLEXCEPT(Data,Data[Device] )
  )
)

 

 

 

This is what TimeLoaded_LC is, and this is what NewRunLadoad gets:

 

 

I want it to take the current value, - previous value. as 988 - 987.9 = 0.1 and this value to be in NewRunLoad. 

 

Thanks!

 

Kind regards

Agnes

  • Hi Anonymous,

     

    Please refer to below DAX formula:

    NewRunLoad =
    IF (
        CALCULATE (
            MAX ( Data[Index] ),
            FILTER ( ALLEXCEPT ( Data, Data[Device] ), [Index] < EARLIER ( Data[Index] ) )
        )
            = BLANK (),
        BLANK (),
        Data[TimeLoaded_LC]
            - CALCULATE (
                SUM ( Data[TimeLoaded_LC] ),
                FILTER (
                    ALLEXCEPT ( Data, Data[Device] ),
                    [Index]
                        = EARLIER ( Data[Index] ) - 1
                )
            )
    )

     

    Best regards,

    Yuliana Gu

2 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    Is this a measure? 

     

    Seems like your > sign in your minIndx VAR should be a < sign.

  • v-yulgu-msft's avatar
    v-yulgu-msft
    Microsoft Employee

    Hi Anonymous,

     

    Please refer to below DAX formula:

    NewRunLoad =
    IF (
        CALCULATE (
            MAX ( Data[Index] ),
            FILTER ( ALLEXCEPT ( Data, Data[Device] ), [Index] < EARLIER ( Data[Index] ) )
        )
            = BLANK (),
        BLANK (),
        Data[TimeLoaded_LC]
            - CALCULATE (
                SUM ( Data[TimeLoaded_LC] ),
                FILTER (
                    ALLEXCEPT ( Data, Data[Device] ),
                    [Index]
                        = EARLIER ( Data[Index] ) - 1
                )
            )
    )

     

    Best regards,

    Yuliana Gu