Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Create filtered table based on selected date

Hello,   I've been stuck with this issue for hours and I need help understanding why this solution isn't working. I've seen the same solution being suggested for others with similar problems as me,...
  • Anonymous's avatar
    Anonymous
    7 years ago

    The issue is that you have created a calculated table. Tables are static, and are only evaluated when the underlying dataset is refreshed...they do NOT update in response to any cross filtering, slicer selection, etc.

     

    So, your code is doing exactly what you told it to: since there is no filter context for the SELECTEDVALUE(), it returns the default value of 2019/01/01.

     

    You can create a measure like this:

    PricesValidForSelectedDate =
    VAR SelectedDate =
        SELECTEDVALUE (
            'Calendar'[Date_ID];
            DATE ( 2019; 1; 1 )
        )
    VAR FilteredPrices =
        FILTER (
            ALL (
                Prices[ValidFromDate];
                Prices[ValidToDate]
            );
            'Prices'[ValidFromDate] <= SelectedDate
                && 'Prices'[ValidToDate] >= SelectedDate
        )
    VAR Result =
        CALCULATE (
            MIN ( Prices[Price Column] );
            FilteredPrices
        )
    VAR Check =
        IF (
            HASONEVALUE ( Prices[<Granular Column>] );
            Result
        )
    RETURN
        Check

    SelectedDate is just as you wrote it.

     

    FilteredPrices uses a more optimized table.  You only need to scan the unique combinations for [ValidFrom] and [ValidTo], you don't need to scan every single row in the prices table (which, when expanded, could produce a large table in memory).

     

    Result returns the price when you have a single product in the the filter context.  I'm guessing you're putting Product on the rows of your table?

     

    Check just makes sure that you display a blank in the subtotal or grand total section of your table/matrix.  Make sure that <Granular Column> is whatever you're putting in the table.

     

    Hope this helps,

     

    ~ Chris