Forum Discussion
Applying Measure after Multiple Selection
- 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 _resultAnd 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
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
Hi Aniya,
Success! Can confirm that worked for me. Thank you 🙂
For the sake of learning, I'm not understanding why if I replace
var _id = VALUES('Product'[Product])with
var _id = VALUES('SalesActual'[Product])
I end up with this chart,
The product column in all three tables consist of the same 2 distinct values 'Broom' and 'Vacuum' so shouldn't it give identical results regardless of which table I select?
Modelwise too I don't really see a difference.
Thanks again.