Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

Modify the calculated measure. The error is in line 8: EARLIER/EARLIEST refers to an…

  1. User

    Modify the calculated measure. The error is in line 8: EARLIER/EARLIEST refers to an earlier row context which doesn't exist.

    Last Date in Group (check) = var _current = MAX(Customer_SKU_Date[Date]) var _next = CALCULATE( MAX(Customer_SKU_Date[Date]), FILTER( ALL(Customer_SKU_Date), Customer_SKU_Date[Rank Customer-SKU] = MAX(Customer_SKU_Date[Rank Customer-SKU]) + 1 && Customer_SKU_Date[Customer-SKU] = EARLIER(Customer_SKU_Date[Customer-SKU]) ) )

    var _datediff = DATEDIFF(_current, _next, DAY)

    RETURN IF(_datediff = 1, 0, 1)

  2. Assistant

    Last Date in Group (check) = var _current = MAX(Customer_SKU_Date[Date]) var _next = CALCULATE( MAX(Customer_SKU_Date[Date]), FILTER( ALL(Customer_SKU_Date), Customer_SKU_Date[Rank Customer-SKU] = MAX(Customer_SKU_Date[Rank Customer-SKU]) + 1 && Customer_SKU_Date[Customer-SKU] = MAX(Customer_SKU_Date[Customer-SKU]) ) )

    var _datediff = DATEDIFF(_current, _next, DAY)

    RETURN IF(_datediff = 1, 0, 1)

  3. User

    It does not work

  4. Assistant

    Apologies for the confusion. Upon further analysis, it seems that the issue lies in the use of EARLIER() function within the CALCULATE() function. The EARLIER() function is used to refer to an earlier row context, but in this case, there is no earlier row context within the CALCULATE() function.

    To resolve this issue, you can modify the calculated measure as follows:

    Last Date in Group (check) = VAR _rank = MAX(Customer_SKU_Date[Rank Customer-SKU]) VAR _current = MAX(Customer_SKU_Date[Date])

    VAR _next = CALCULATE( MAX(Customer_SKU_Date[Date]), FILTER( ALL(Customer_SKU_Date), Customer_SKU_Date[Rank Customer-SKU] = _rank + 1 && Customer_SKU_Date[Customer-SKU] = MAX(Customer_SKU_Date[Customer-SKU]) ) )

    VAR _datediff = DATEDIFF(_current, _next, DAY)

    RETURN IF(_datediff = 1, 0, 1)

    In this modified version, we store the value of MAX(Customer_SKU_Date[Rank Customer-SKU]) in a separate variable (_rank) before using it in the CALCULATE() function. This avoids the need to use the EARLIER() function.