Forum Discussion
Calculated column (CALCULATE + FILTER) from the same table
- 4 years ago
CarlsBerg999 so yes, it's because of your max you did in the beginning. I suspected right 🙂
Try this:Project ID = VAR CurrentRowSO = 'Sales'[Sales Order ID] VAR Task_ID = MAXX(FILTER('Sales', 'Sales'[Sales Order ID] = CurrentRowSO), 'Sales'[Task ID]) RETURN CALCULATE ( LEFT ( Task_ID, LEN ( Task_ID ) - ( LEN ( Task_ID ) - FIND ( "-", Task_ID ) + 1 ) ), 'Sales'[Task ID] <> BLANK (), 'Sales'[Sales Order ID] = CurrentRowSO )
CarlsBerg999 I'm not sure what you are trying to calculate and it's strange that you used MAX on the 1st var but maybe that's what you need.
The max gives you the maximum task of all the rows (as it's being evaluted for a calcaulted column and there for doesn't have any filter context at the point you execute it). Maybe you wanted something else there, let's say the max for that order or something.
Anyway try this 1st (didn't touch the max aspect):
Project ID =
VAR Task_ID = MAX('Sales'[Task ID])
VAR CurrentRowSO = 'Sales'[Sales Order ID]
RETURN
CALCULATE (
LEFT (
Task_ID,
LEN ( Task_ID )
- (
LEN ( Task_ID ) - FIND ( "-", Task_ID ) + 1
)
),
'Sales'[Task ID] <> BLANK (),
'Sales'[Sales Order ID] = CurrentRowSO
)
- CarlsBerg9994 years agoHelper V
This produced the same result as my code (=incorrect). The table below shows a part of the actual table and the hoped outcome. The code above (as well as mine) returned P99, which is incorrect and ignores the filter that says Sales Order ID must be CurrentRowSO.
Sales Order ID Sales Order Line Item ID SO ID & SO Line Item ID Item Cancel ID Item Cancel Text Task ID Project ID 606 20 606-20 1 Not Canceled P88 606 10 606-10 1 Not Canceled P88-2 P88 - SpartaBI4 years agoCommunity Champion
CarlsBerg999 so yes, it's because of your max you did in the beginning. I suspected right 🙂
Try this:Project ID = VAR CurrentRowSO = 'Sales'[Sales Order ID] VAR Task_ID = MAXX(FILTER('Sales', 'Sales'[Sales Order ID] = CurrentRowSO), 'Sales'[Task ID]) RETURN CALCULATE ( LEFT ( Task_ID, LEN ( Task_ID ) - ( LEN ( Task_ID ) - FIND ( "-", Task_ID ) + 1 ) ), 'Sales'[Task ID] <> BLANK (), 'Sales'[Sales Order ID] = CurrentRowSO )- CarlsBerg9994 years agoHelper V
This works. What are we doing in this code differently. In the variable, the Task_ID apparently iterates through the entire table (which is filtered by the CurrentRowSO), looking for the largest figure. The largest figure is never "blank".
--> Do we even need the calculate function?
Project ID = VAR CurrentRowSO = 'ODATA | Biovian | Sales Order Volume Extended'[Sales Order ID] VAR Task_ID = MAXX(FILTER('ODATA | Biovian | Sales Order Volume Extended','ODATA | Biovian | Sales Order Volume Extended'[Sales Order ID]=CurrentRowSO),'ODATA | Biovian | Sales Order Volume Extended'[Task ID]) RETURN LEFT ( Task_ID, LEN ( Task_ID ) - ( LEN ( Task_ID ) - FIND ( "-", Task_ID ) +1 ) )