Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
ABC11
Resolver I
Resolver I

Look up laborcode in another row in same table in Dax

Hi,

I have laborcode(employee no), name and laborhrs in one row

And euipment, equipmenthrs , equilaborcode in different row. 

Laborcode and equilaborcode is same.  I would like to identify operator by name.

I did create column

Operator_name = if('LEM FACT with query'[EQUIPLABORCODE]='LEM FACT with query'[LABORCODE],'LEM FACT with query'[EMPLOYEE_NAME],"No Name")
But not working for me.
Also possible I need the oparator total hrs in last column as well for that day.
Last two column are output column
WorkdateLaborcodenamelaborhrsequipmentEquipment hrsEquipmentlaborcodevendequipmentunitOperator_nameOprator total hrs
12/1/202230017091Landry0.5      
12/1/202230004386LETENDRE3      
12/1/202230012147Penkov0.5      
12/1/202230004376ROY2.5      
12/1/202230004393Vergunov3      
12/1/202230004376ROY5.5      
12/1/202230004393Vergunov5      
12/1/202230004393Vergunov2      
12/1/2022   160 TON4.530004393160-1-4433Vergunov10
12/1/2022    160 TON730004376160-1-4433ROY12.5
12/1/202230004376ROY2      
12/1/202230004376ROY2.5      
12/1/202230017091Landry2      
12/1/202230017091Landry1      
12/2/202230004370BANARES0.5      
12/2/202230017091Landry0.5      
12/2/202230004370BANARES1      
12/2/2022   100 TON230004370100-1-4617BANARES10
12/2/202230004370BANARES7.5      
12/2/202230004370BANARES1      
12/2/2022   100 TON630017091100-1-4475Landry11
12/2/202230017091Landry7.5      
12/2/202230017091Landry2      
12/2/202230017091Landry1      
 
 
Thanks lots
1 ACCEPTED SOLUTION

You can change Operator Total Hrs2 to Return _calc now.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

20 REPLIES 20
jgeddes
Super User
Super User

Sure.
Share your formulas for both Operator Name and for Operator Total Hours.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Only this is not working. 
Operator Total HRs =
CALCULATE(
sum('LEM FACT with query'[LABORHRS]),
ALLEXCEPT('LEM FACT with query','LEM FACT with query'[EMPLOYEE_NAME],'LEM FACT with query'[WORKDATE]))
 
Operator Name formula is working
 
Thanks 

I just needed to see what you named the Operator Name column.
The name column that is referenced in the ALLEXCEPT statement needs to be the "Operator Name" column, not the original Employee Name column.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





 When I change to OpratorName column still not working
Operator Total HRs =
CALCULATE(
sum('LEM FACT with query'[LABORHRS]),
ALLEXCEPT('LEM FACT with query','LEM FACT with query'[OparatorName],'LEM FACT with query'[WORKDATE]))
 
OparatorName =
var _nameLookUp=
LOOKUPVALUE('LEM FACT with query'[EMPLOYEE_NAME],'LEM FACT with query'[LABORCODE],'LEM FACT with query'[EQUIPLABORCODE])
Return
if(
or(ISBLANK(_nameLookUp), _nameLookUp=""),
'LEM FACT with query'[EMPLOYEE_NAME],
_nameLookUp
)
Please,
Thanks for your help

Ok, let us change the Operator Total Hours calculated column to this...

Operator Total Hours2 = 
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

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Sorry- Didn't work
 
Operator Total HRs2 =
VAR _OperatorName=
'LEM FACT with query'[OparatorName]
VAR _workdate=
'LEM FACT with query'[WORKDATE].[Date]
VAR _calc =
Calculate(
sum('LEM FACT with query'[LABORHRS]),
FILTER(ALL('LEM FACT with query'),'LEM FACT with query'[OparatorName]=_OperatorName && 'LEM FACT with query'[WORKDATE].[Date]=_workdate)
)
Return
_calc
 
Please, look it again for me
Thanks

Ok, replace the "_calc" with _OperatorName and see if the names are returned.

Then replace _calc with _workdate and see if the workdates are returned.

Let me know how that works





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





When I replace _calc with Operatorname then retuen Operatorname.

When I replace _calc with Workdate tehn return Workdate.

But I need total hrs.

Thanks

Rupal

Thanks. That allows me to know that there are no errors in the data. 

When you use 

Operator Total Hours2 = 
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

What data values or errors are returned? Could you grab a screen shot of the results?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Sorry for late reply. It coming out blank(no data, no error)

ABC11_0-1670859418547.png

 

Thanks

 

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

  





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





I greatly appriciate your time
 
No data(blank)and no error
 
Operator Total HRs2 =
VAR _RowHours=
'LEM FACT with query'[LABORHRS]
VAR _OperatorName=
'LEM FACT with query'[OparatorName]
VAR _workdate=
'LEM FACT with query'[WORKDATE]
VAR _calc =
Calculate(
SUM('LEM FACT with query'[LABORHRS]),
FILTER(ALL('LEM FACT with query'),'LEM FACT with query'[OparatorName]=_OperatorName && 'LEM FACT with query'[WORKDATE]=_workdate)
)
Return
_RowHours
 
 

Well now we are getting somewhere.
Going back to the beginning...

We started with...

jgeddes_0-1670866317174.png

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...

jgeddes_1-1670866879978.png

Can you verify that this is the result you get?

Let me know how these work and we will go from there.

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Its not pulling Operator name for employee_name.

ABC11_0-1670867960548.png

 

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
)

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





jgeddes
Super User
Super User

You can add the following calculated columns...

operatorName = 
var _nameLookup =
LOOKUPVALUE(codeTable[name],codeTable[Laborcode],codeTable[Equipmentlaborcode])
Return
IF(
    OR(ISBLANK(_nameLookup), _nameLookup=""),
    [name],
    _nameLookup
)

and 

Operator Total Hours = 
CALCULATE(
    SUM(codeTable[laborhrs]),
    ALLEXCEPT(codeTable, codeTable[operatorName], codeTable[Workdate])
)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Now Operator Name is pulling. What is our next step? please

ABC11_1-1670869247879.png

 

You can change Operator Total Hrs2 to Return _calc now.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Perfect!

Thanks lots for your help

Thanks lot to Solution Sage,

Operator name is working fine but Operator Total hours coming blank. Would you help me to figure out.

Thanks again

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

Check out the March 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors