Forum Discussion

Palmtop's avatar
Palmtop
Helper I
3 years ago
Solved

Applying Measure after Multiple Selection

Hello All,    I have a measure that extrapolates a curve based off the ratio between the latest data point and another line.  While it works fine for a single selection, it does not work as intende...
  • v-yueyunzh-msft's avatar
    3 years ago

    Hi , Palmtop 

    According to your description, you want to update the [Forcast] measure to meet the "Applying Measure after Multiple Selection". Right?

    Here are the steps you can refer to :

    I download you .pbix file and test in  my side , you can create a measure to replace your [Forcast] measure:

    Forecast2 = 
    // Finds latest sales date
    VAR EvalDate =
        CALCULATE(
            MAX ( SalesActual[Date] ),
            ALLSELECTED ( SalesActual )
        )
    var BoundaryDate = EOMONTH( TODAY(), -2 ) + 1
    VAR Date_ =
        // If latest sales date is older than 2 months, 
        // it will default back to current month.
        IF ( EvalDate < BoundaryDate, 
            BoundaryDate,
            EvalDate
        )
    var _id = VALUES('Product'[Product])
    VAR SalesHistorical = 
        CALCULATE(
            [Actual Sales],
            'Calendar'[Date] = Date_,
            SalesHighLow[Product] in _id
        )
    VAR SalesHigh =
        CALCULATE (
            // Value of sales high curve @ Date_
            [High Sales],
            'Calendar'[Date] = Date_,
            SalesHighLow[Product] in _id
        )
    VAR SalesLow =
        CALCULATE (
            // Value of sales low curve @ Date_
            [Low Sales],
            'Calendar'[Date] = Date_,
            SalesHighLow[Product] in _id
        )
    
    var _cat = SWITCH(
                    TRUE(),
                    SalesHistorical <= SalesLow, 1,
                    SalesHistorical <= SalesHigh, 2,
                    SalesHistorical >= SalesHigh, 3
                    )
    
    var _result = IF ( MIN('Calendar'[Date]) >= Date_, 
        SWITCH ( 
        TRUE(),   // TRUE used as first argument allows SWITCH to replace nested IFs  Cleaner to read. 
        _cat = 1, CALCULATE( [Low Sales] * DIVIDE(SalesHistorical, SalesLow) ),
        _cat = 2, CALCULATE( ( [High Sales] * (SalesHistorical - SalesLow) + [Low Sales] * (SalesHigh - SalesHistorical) ) / (SalesHigh - SalesLow) ) ,
        _cat = 3, CALCULATE( [High Sales] * (SalesHistorical/ SalesHigh) ) 
        )
    )
    
    return
        _result

    And then we will meet your need:

     

     

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly