Forum Discussion

Jean_Ferro's avatar
Jean_Ferro
Icon for Helper I rankHelper I
2 years ago

Getting unexpected exception with measure

Hello everyone!

I am creating this measure that works as needed only if I keep the date fixed like DATE(2024, 6, 10), if I try to make the date dynamic using a measure that returns the greatest date chosen by the user in the calendar like this:

maxx(dCalendar,[Date])

I get the error "unexpected exception"


SUMX(
ADDCOLUMNS(
SUMMARIZE(
FILTER(
fStock,
fStock[DTABASE] <= DATE(2024, 6, 10)
),
fStock[PRODUCT_CODE],
fStock[BRANCH],
"MaxDate", MAX(fStock[DTABASE])
),
"Cost",
CALCULATE(
MAX(fStock[COST]),
FILTER(
fStock,
fStock[DTABASE] = [MaxDtaEntradaSaida] &&
fStock[PRODUCT_CODE] = EARLIER(fStock[PRODUCT_CODE]) &&
fStock[BRANCH] = EARLIER(fStock[BRANCH])
)
)
),
[Cost]
)


 

8 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Icon for Community Champion rankCommunity Champion

    Jean_Ferro What about just MAX('dCalendar'[Date])

    or:

    Measure = 
    VAR __Date = MAX('dCalendar'[Date])
    VAR __Result = 
    SUMX(
    ADDCOLUMNS(
    SUMMARIZE(
    FILTER(
    fStock,
    fStock[DTABASE] <= __Date
    ),
    fStock[PRODUCT_CODE],
    fStock[BRANCH],
    "MaxDate", MAX(fStock[DTABASE])
    ),
    "Cost",
    CALCULATE(
    MAX(fStock[COST]),
    FILTER(
    fStock,
    fStock[DTABASE] = [MaxDtaEntradaSaida] &&
    fStock[PRODUCT_CODE] = EARLIER(fStock[PRODUCT_CODE]) &&
    fStock[BRANCH] = EARLIER(fStock[BRANCH])
    )
    )
    ),
    [Cost]
    )
    RETURN
      __Result
    • Jean_Ferro's avatar
      Jean_Ferro
      Icon for Helper I rankHelper I

      Unfortunately the same unexpected exception error, if I change it to DATE(2024,6,5) for example it works, but I need it to be dynamic.

      The measure to return the greatest date seems correct to me:



      GreatestDataStock = maxx(dCalendar,[Date])

       

      • Greg_Deckler's avatar
        Greg_Deckler
        Icon for Community Champion rankCommunity Champion

        Jean_Ferro Any chance you can post a link to the file? Otherwise it's really hard to understand what is going on here.