Forum Discussion

nbufff's avatar
nbufff
Icon for Helper I rankHelper I
1 year ago
Solved

Get value from previous row by DAX

Hello, I stuck in the DAX formual by tring to get value from previous row.

 

With Below example, when Date and SKU are same:

D3=D2

D4=D3

D6=D5

....

How can we achieve that by adding Column D (Qty2) in using DAX?

 

 

Thanks for help!

  • nbufff Hi! Create a new calculated column with this code:

    Qty2_col =
    VAR CurrentDate = 'Table'[Date]
    VAR CurrentSKU = 'Table'[SKU]
    VAR CurrentQty1 = 'Table'[Qty1]

    VAR PreviousQty =
        CALCULATE(
            MIN('Table'[Qty1]),
            FILTER(
                'Table',
                'Table'[Date] = CurrentDate &&
                'Table'[SKU] = CurrentSKU &&
                'Table'[Qty1] > CurrentQty1
            )
        )

    RETURN
    IF(
        ISBLANK(PreviousQty),
        0,
        PreviousQty
    )

     

    if it's ok, please accept my answer as solution!

     

    BBF

2 Replies

  • BeaBF's avatar
    BeaBF
    Icon for Super User rankSuper User

    nbufff Hi! Create a new calculated column with this code:

    Qty2_col =
    VAR CurrentDate = 'Table'[Date]
    VAR CurrentSKU = 'Table'[SKU]
    VAR CurrentQty1 = 'Table'[Qty1]

    VAR PreviousQty =
        CALCULATE(
            MIN('Table'[Qty1]),
            FILTER(
                'Table',
                'Table'[Date] = CurrentDate &&
                'Table'[SKU] = CurrentSKU &&
                'Table'[Qty1] > CurrentQty1
            )
        )

    RETURN
    IF(
        ISBLANK(PreviousQty),
        0,
        PreviousQty
    )

     

    if it's ok, please accept my answer as solution!

     

    BBF