Forum Discussion
Look up laborcode in another row in same table in Dax
- 3 years ago
You can change Operator Total Hrs2 to Return _calc now.
This is a bit of a head scratcher.
Can you add a test for labour hours into the code as follows and then return _rowHours and let me know. The basic premise is that we added the operator name to each row in the table and now we are doing a simple sum for each operator for each workdate.
Operator Total Hours2 =
var _rowHours =
codeTable[labourhrs]
var _operatorName =
codeTable[operatorName]
var _workDate =
codeTable[Workdate]
var _calc =
CALCULATE(
SUM(codeTable[laborhrs]),
FILTER(ALL(codeTable), codeTable[operatorName] = _operatorName && codeTable[Workdate] = _workDate)
)
Return
_calc
- jgeddes3 years ago
Super User
Well now we are getting somewhere.
Going back to the beginning...We started with...
If you created a calculated column at this point that was
RowHours = codeTable[labourhrs]
It should just pull the labour hours over for all rows except the equipment rows.
Can you double check that this happens in your data?
Assuming that works correctly, we added the Operator Name to each row.
operatorName =
var _nameLookup =
LOOKUPVALUE(codeTable[name],codeTable[Laborcode],codeTable[Equipmentlaborcode])
Return
IF(
OR(ISBLANK(_nameLookup), _nameLookup=""),
[name],
_nameLookup
)All this is doing looking in the labourcode column for the Equipmentlabourcode and returning whatever the name is for that row. The Equipmentlabourcode and labourcode need to be in the same format for this to work. If this worked correctly the table that results should look like...
Can you verify that this is the result you get?
Let me know how these work and we will go from there.
- ABC113 years ago
Resolver I
Its not pulling Operator name for employee_name.
- jgeddes3 years ago
Super User
I think I see it...
Replace the code as follows (in bold)...
operatorName =
var _nameLookup =
LOOKUPVALUE(codeTable[name],codeTable[Laborcode],codeTable[Equipmentlaborcode])
Return
IF(
OR(_nameLookup=",", _nameLookup=""),
[name],
_nameLookup
)