To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.
Hi!
The task is for the user to select a year on the slicer and get two results:
I can't use a "date" to find a previous order - one customer may have several different products that can't be mixed, and related orders are not necessarily in neighboring years. But we have a unique serial number for each order and information about the serial number of the previous order, through which they can be linked.
Choosing 2018 in slicer, we should get:
It is better to do this through a "measure" rather than a "calculated column".
Example table:
https://drive.google.com/file/d/1p7LSf7rBcJcTG_zG4E4g_k_0sjXT_Qfz/view?usp=sharing
Hi Alex,
I have a solution that works (on the sample set):
I have used 3 measures. The one for previous order is just to show which order is selected as previous.
Previous Order =
var CurrentOrder = Max(orders[Serial])
return CALCULATE(max(orders[Serial]), filter( all(Orders), Orders[Serial]<CurrentOrder))
Previous Price =
var CurrentOrder = Max(orders[Serial])
var CurrentClient = Max(Orders[Client])
var CurrentProduct = Max(Orders[Product])
var PreviousOrder = CALCULATE(max(orders[Serial]), filter( all(Orders), Orders[Serial]<CurrentOrder))
var PreviousPrice = LOOKUPVALUE('Orders'[Price], Orders[Serial] , PreviousOrder, Orders[Client], CurrentClient, Orders[Product], CurrentProduct)
var Result = PreviousPrice
return
Result
Previous Price 2 =
if (HASONEVALUE(Orders[Serial]), [Previous Price], sumx(ALLSELECTED(Orders), [Previous Price]))
Previous Price 2 is what calculates the correct total. (I did not bother too much about the looks of the table as long as the result is correct 🙂 )
I have the feeling that there a more elegant solutions available, but this is how far my expertise brings me, hope it helps.
Jan
User | Count |
---|---|
14 | |
11 | |
6 | |
6 | |
5 |
User | Count |
---|---|
29 | |
17 | |
11 | |
7 | |
5 |