Forum Discussion

eddd83's avatar
eddd83
Resolver I
5 years ago
Solved

keep filter ( ) + filter ( all ( ) )

slicer: 

Date[Date] = Oct 24, 2020 (saturday)

 

Report:

LocationProductPosted Price
ChicagoApples1.25
ChicagoBanana1.75
ChicagoCarrots1.61

 

Produce Table:

LocationProductPosted PriceDate
ChicagoApples1.2510/23/20
ChicagoApples2.1210/24/20
ChicagoApples2.5110/25/20
ChicagoBanana1.7510/23/20
ChicagoBanana2.6510/24/20
ChicagoBanana2.7510/25/20
ChicagoCarrots1.6110/23/20
ChicagoCarrots2.4510/24/20
ChicagoCarrots2.4110/25/20
Chicago Mango0.7510/23/20

 

 

 

 

 

posted price =
VAR WeekDays =
    IF ( HASONEVALUE ( Dates[Date] ), VALUES ( Dates[Day Short] ), "Mon" )
VAR SelDate =
    IF ( HASONEVALUE ( Dates[Date] ), VALUES ( Dates[Date] ), TODAY () )
VAR PostedPricesWeekday =
    CALCULATE (
        MIN ( 'Posted Prices'[Price] ),
        'Posted Prices'[Price Date]
            = IF ( HASONEVALUE ( Dates[Date] ), VALUES ( Dates[Date] ), TODAY () )
    )
VAR PostedPricesSat =
    CALCULATE (
        MIN ( 'Posted Prices'[Price] ),
        KEEPFILTERS (
            FILTER (
                ALL ( 'Posted Prices'[Price Date] ),
                'Posted Prices'[Price Date] = SelDate - 1
            )
        )
    )
VAR PostedPricesSun =
    CALCULATE (
        MIN ( 'Posted Prices'[Price] ),
        KEEPFILTERS (
            FILTER (
                ALL ( 'Posted Prices'[Price Date] ),
                'Posted Prices'[Price Date] = SelDate - 2
            )
        )
    )
RETURN
    IF (
        WeekDays = "Sat",
        PostedPricesSat,
        IF ( WeekDays = "Sun", PostedPricesSun, PostedPricesWeekday )
    )

 

 

 

 

 

There's a many to 1 relationship between produce table [date] and date [date].

 

Even though the slicer says 10/24/2020, I want to show the last available weekday price, which is 10/23/2020 (friday) in this case. I have included filter ( all ( ) ) in my measure, otherwise, the 10/24/2020 filter context would only return the saturday value. However, I would still like to keep the filter context for location & product because otherwise my measure would return 0.75 (from mangos). I tried using Keepfilters, but i'm not achieving my desired result.

 

Help?

  • eddd83 not sure if you would like it, but I solved it using a different measure.

     

     

    Revised Price := 
    VAR _1 = MAX(Dates[Date])
    VAR _2 = CALCULATE(MAX(Dates[Date]),FILTER(ALL(Dates),Dates[Date]<=_1&&[Max Revised date]<>0))
    VAR _3 = CALCULATE([MaxPrice],ALL(Dates[Date]),Dates[Date]=_2)
    RETURN _3

     

5 Replies

  • eddd83 , Not very clear. You can have a date table with following columns

     

    WeekDay = WEEKDAY([Date],2) //monday
    Start of Week = [Date] -[WeekDay]+1 //monday
    Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)

     

    Measure  =

    var _max = maxx(allselected('Date'), 'Date'[Week Rank])

    return

    Calculate(min(Produce[Posted Price]) , filter(All('Date'), 'Date'[Week Rank]) =_max))

     

    To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

  • smpa01's avatar
    smpa01
    Community Champion

    eddd83 not sure if you would like it, but I solved it using a different measure.

     

     

    Revised Price := 
    VAR _1 = MAX(Dates[Date])
    VAR _2 = CALCULATE(MAX(Dates[Date]),FILTER(ALL(Dates),Dates[Date]<=_1&&[Max Revised date]<>0))
    VAR _3 = CALCULATE([MaxPrice],ALL(Dates[Date]),Dates[Date]=_2)
    RETURN _3