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
If you select many items, then... what is the latest sale date? Is it for broom or the other item? They can have different last sales dates, right? So then, which one do you want to use? This is not as straightforward as you might think. You have to ponder over what you want to do in such cases very thoroughly...
- Palmtop3 years agoHelper I
Hi daXtreme,
Thanks again for the help last time.
Regarding the question you pose, I'd like it so that when you select multiple items, you would sum the sales data to get a new dataset/curve (seen in Case 3) and the measure would treat it as a new independent dataset instead of one which is a sum of 2 others.
It would recalculate a ratio, latest sale date, latest sale #, and extrapolate it from there.
So, sum cases --> calculate measure instead of calculate measure for each case --> sum result.
Simpler answer would be whichever is the most recent.
So in an example case it would apply the measure to 'Total' taking 04/22 as the latest sale date.
Date Broom Vacuum Total 01/22 10 0 10 02/22 15 5 20 03/22 0 7 7 04/22 n/a 7 7 Retaking the original cases, the desired result would look like the yellow line:
Please let me know if its still confusing. Thank you.
- daXtreme3 years agoSolution Sage
Can you please supply the data set?