Forum Discussion

PatrickLamoste's avatar
6 years ago
Solved

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.

 

  • v-lili6-msft's avatar
    v-lili6-msft
    6 years ago

    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:

     

    and here is sample pbix file, please try it.

     

    Regards,

    Lin

7 Replies

  • 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
  • v-lili6-msft's avatar
    v-lili6-msft
    Icon for Community Support rankCommunity 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:

     

    and here is sample pbix file, please try it.

     

    Best Regards,

    Lin

    • PatrickLamoste's avatar
      PatrickLamoste
      Icon for Helper I rankHelper I

      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.

       

       

       

       

       

       

       

       

      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

       

      • v-lili6-msft's avatar
        v-lili6-msft
        Icon for Community Support rankCommunity Support

        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