DAX use slicer selection in calculate statement

Viewed 485

I am trying to use a calculate statement with a measure to filter results of a table but I need the values to change if the user selects 1 date from a slicer. Below is the code I am using.

PCurrentDay = calculate(sum('Sheet0 (2)'[Toys_Count]),datediff('Sheet0 (2)'[SCAN_Date],'Sheet0 (2)'[SHIP_Date],DAY)=0)

This returns a value but it won't update if the user selects a specific scan date. Any ideas?

1 Answers

Can you replace the measure with following

Measure =
CALCULATE (
    SUM ( 'Table'[val] ),
    FILTER (
        'Table',
        DATEDIFF (
            CALCULATE ( MAX ( 'Table'[scan] ) ),
            CALCULATE ( MAX ( 'Table'[ship] ) ),
            DAY
        ) = 0
    )
)

CALCULATE inside DATEDIFF provides the correct context for the filter to work.

Related