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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply

Sum with ID and Date from a different table

Hi,

 

I am currently working on 2 tables. The 1st table has the regular hours and the 2nd one has the OT hours.

 

What I am trying to achieve is to have the OT hours in  a new column in the Regular Hours table. I already tried LOOKUPVALUE but it gave me an error.

 

Attached is the xlsx file.

 

Thank you in advance.

 

image.png

1 ACCEPTED SOLUTION

hi, @PatrickLamoste 

For your case, you need to create a new table by this formula:

Table = 
SUMMARIZE (
    Table1,
    Table1[Employee ID],
    Table1[Date],
    "Regular Hours", CALCULATE ( SUM ( Table1[Hours] ) ),
    "OT Hours", CALCULATE (
        SUM ( Table2[Hours] ),
        FILTER (
            Table2,
            Table2[Employee ID] = Table1[Employee ID]
                && Table2[Date] = Table1[Date]
        )
    )
)

Result:

1.JPG

 

and here is sample pbix file, please try it.

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
v-lili6-msft
Community Support
Community Support

hi, @PatrickLamoste 

You could try these two formulas as below:

Column = 
LOOKUPVALUE (
    Table2[OT Hours],
    Table2[ID], Table1[ID],
    Table2[Date], Table1[Date]
)
Column 2 =
CALCULATE (
    SUM ( Table2[OT Hours] ),
    FILTER ( Table2, Table2[ID] = Table1[ID] && Table2[Date] = Table1[Date] )
)

Result:

3.JPG

 

and here is sample pbix file, please try it.

 

Best Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hello Lin @v-lili6-msft ,

 

I tried the LOOKUPVALUE but it does not work for me it gave this error. It seems that there are some entries with repeated values (EID and Date). Below is my actual list. I also tried the 2nd formula and it gave incorrect values.

 

Thank you so much for your help.

 

Capture.PNG

 

 

 

 

 

 

 

Table 1   
Employee IDHour TypeDateHours
110290Regular Hours01/04/201910.00
110290Regular Hours02/04/20197.00
110290Regular Hours03/04/20198.00
110290Regular Hours04/04/20193.00
110290Regular Hours04/04/20196.00
110290Regular Hours05/04/20193.00
110290Regular Hours05/04/20193.00
110290Regular Hours08/04/201912.00
110290Regular Hours09/04/201911.00
110290Regular Hours10/04/20190.00
110290Regular Hours10/04/201910.00
110290Regular Hours11/04/20197.00
110290Regular Hours11/04/20190.00
110290Regular Hours12/04/201910.00
110290Regular Hours15/04/20192.00
110290Regular Hours15/04/20194.00
110290Regular Hours15/04/20194.00
110290Regular Hours16/04/20192.00
110290Regular Hours16/04/20195.00
110290Regular Hours17/04/20192.00
110290Regular Hours17/04/20194.00
110290Regular Hours17/04/20192.00
110290Regular Hours18/04/20191.00
110290Regular Hours18/04/20191.00
110290Regular Hours18/04/20197.00
110290Regular Hours22/04/20195.00
110290Regular Hours23/04/20192.00
110290Regular Hours23/04/20193.00
110290Regular Hours23/04/20193.00
110290Regular Hours24/04/20191.00
110290Regular Hours24/04/20193.00
110290Regular Hours24/04/20192.00
110290Regular Hours25/04/20192.00
110290Regular Hours25/04/20192.00
110290Regular Hours25/04/20195.00
110290Regular Hours26/04/20191.00
110290Regular Hours26/04/20194.00
110290Regular Hours26/04/20193.00
110290Regular Hours29/04/20193.00
110290Regular Hours30/04/20191.00

 

Table 2   
Employee IDHour TypeDateHours
110290OT Hours01/04/201910.00
110290OT Hours02/04/20197.00
110290OT Hours03/04/20198.00
110290OT Hours04/04/20199.00
110290OT Hours05/04/20196.00
110290OT Hours08/04/201912.00
110290OT Hours09/04/201911.00
110290OT Hours10/04/20197.00
110290OT Hours15/04/201910.00
110290OT Hours16/04/20197.00
110290OT Hours17/04/20198.00
110290OT Hours18/04/20199.00
110290OT Hours23/04/20198.00
110290OT Hours24/04/20192.00
110290OT Hours24/04/20193.00
110290OT Hours24/04/20192.00
110290OT Hours25/04/20197.00
110290OT Hours29/04/201910.00
110290OT Hours30/04/20198.00

 

hi, @PatrickLamoste 

Yes, the problem is that there are some entries with repeated values (EID and Date), So you could not use LOOKUPVALUE in this case.

For your requirement, you have to aggregate [Hours] value by SUM/MIN/MAX as 2nd formula, otherwise, what is the expected output for [Employee ID] 110290 and [Date] 24/04/2019?

 

Regards,

Lin

 

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-lili6-msft  Lin,

 

Thank you for your reply. I tried to tweak the formula a bit but still a dead end.

 

I was wondering if it's possible to summarize Table2 [OT] and will be put into Table1 [RegularHours]. But since Table 1 has duplicate dates I need to only display 7 and not the sum of the whole row when  I put it in a visual. Like this.

 

Table1    
Employee IDHour TypeDateHoursOT Hours Sum
110290Regular Hours24/04/201917
110290Regular Hours24/04/201937
110290Regular Hours24/04/201927

 

Table2   
Employee IDHour TypeDateHours
110290OT Hours24/04/20192
110290OT Hours24/04/20193
110290OT Hours24/04/20192

 

So when I put in a table visual it would look like this:

 

Visual: Table   
Employee IDDateRegular HoursOT Hours
11029024/04/201967

 

Hi,

If your end objective is to show Regular and OT hours in a single Table visual, then you need not bring over OT hours from Table2 into Table1.  If my approach looks suitable to you, then post back and I will share my solution with you.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

hi, @PatrickLamoste 

For your case, you need to create a new table by this formula:

Table = 
SUMMARIZE (
    Table1,
    Table1[Employee ID],
    Table1[Date],
    "Regular Hours", CALCULATE ( SUM ( Table1[Hours] ) ),
    "OT Hours", CALCULATE (
        SUM ( Table2[Hours] ),
        FILTER (
            Table2,
            Table2[Employee ID] = Table1[Employee ID]
                && Table2[Date] = Table1[Date]
        )
    )
)

Result:

1.JPG

 

and here is sample pbix file, please try it.

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

IDDateRegular Hours
101/04/20197.00
102/04/20197.00
204/04/20197.15
205/04/20196.85
308/04/20198.00
309/04/20197.00
310/04/20198.50
311/04/20198.50
412/04/20193.00
415/04/20197.00
416/04/20194.50
517/04/20198.00
518/04/20197.50
521/04/20194.50
523/04/20199.50
624/04/20199.00
625/04/20199.50
630/04/20197.00

 

 

IDDateOT Hours
101/04/20192.00
204/04/20194.00
205/04/20193.00
308/04/20192.00
309/04/20192.00
310/04/20194.00
311/04/20193.00
412/04/20192.00
416/04/20191.00
518/04/20191.50
521/04/20192.50
523/04/20193.50
624/04/20194.00
625/04/20193.00

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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