How do I Sum If?

New Day, New Question :smiley:

I have the following Table:

Now First I have Test Times, which is basically just a link to table, to do lookups, second I have times, which lookups all times that I entered in a specific table and is linked to a certain employee. So EMP1 has 5 time entries, therefore lookup field “Times” shows me 5 different values. Lastly I have the field “Billable”, which is a Bolean field in the original table and basically just shows if a time entry is marked as billable or not (If billable Bolean field is marked by a check sign). So you see there are 5 times, the first four are checked and the last one is not checked. Is there a possibility to sum only the times that are checked and if yes how?

I already summed all time entries, but I want to sum only the money that are marked as billable in the Boolean field as well.

Thank you so much and kind regards,

Tom

Hey Tom :slight_smile:

This is possible by using filter.

You can do something like this:

sum(filter(field('Times'), field('Billable?') = true))

Or in short:

sum(filter(field('Times'), field('Billable?')))

This basically filters the field Times based on if Billable? is true and then runs sum over the items remaining.

That should do the trick?

FYI, you can also do this without the lookups if you don’t need the lookup fields in that table for anything else. You can replace field in the formula above with lookup and it will lookup the value from the other table using the formula.

1 Like

Hello,

I am interested in using the formula similar to SUMIF but I can’t find the way. I have tried with sum(filter) and with if() but I can’t do it. I put it in this conversation because I think it is related to what has been discussed.

The situation is the following:
I have a table where I put the total hours worked in each project. In one day, different amounts of hours are entered in separate rows.

What I want to do:
I would like to sum all the hours in the “Hours Quantity” column, if the “Date” column matches the “Date2” column.
In this way I will have the total hours worked each day. In the end I will have a list with the 365 days and the total sum of hours worked.

Can anyone help me?

thanks

Hey @az-bsr

As I understand, you have already filtered accepted records into the “Total hours” column.
You just need to sum the values of that column (at the bottom line), and that is

1 Like

Hello @AlexP,

Thanks for your quick response.
The “Total hours” column is the formula I’m trying to get, it’s not displayed correctly in the screenshot.

The correct information in the Total Hours column would be:

  • Row 1: 12 (because 10h and 2h were entered on 16/10/2024)
  • Row 2: 3 (because 2h and 1h were entered on 15/10/2024)
  • Row 3: 0 (because there are no hours entered on 14/10/2024)
  • Row 4: 0 (because there are no hours entered on 13/10/2024)

The formula should sum all the hours of “Hours Quantity”, which match in the “Date” column with the “Date2” column.

It’s impossible to achieve what you want inside a single table.
But you can do this by adding an additional table and reorganizing your fields a bit.

Here is how I did that:

  1. We need to create the first table “Year presentation”. Here we will have a list of days (365 as you said) and later sum of hours spent on each day will be added here also
  2. Here we need to have just one column, “Date”. Here we need to add each day (screenshot #1)
  3. Then we need a second table, where we will track spent hours on each project (this is similar to the table that you have currently). My table will have the name “Project tracking”.
  4. In that second table we need the same columns as in your table “Project” and “Hours”.
  5. Now we need to link “Year” table into second table. Add new column of type “Link to table”, select our first table, and make sure the checkbox “Create related field…” is checked (screenshot #2)
  6. Now to set the date which we want to track, we need to select a needed day from that linked field (screenshot #3)
  7. In our “Year” table we will have “link to table” column. We need to add another field of lookup type, so select type Lookup, select our Projects table, and field “Hours”.
  8. That’s it! Now we have number of hours near each day. The last step is to add Formula field in our Year table which will sum “Lookup” field (sum(field('Lookup'))). Now we have final version (the last screenshot)




Hello @AlexP,

Thank you very much for your answer, I would have never thought I could do it like this, amazing!

Although it is not the best solution for me, since I have a more complex task registration system, where it is important to have the date when the task was performed in a date field and not a list of related days in a table (for example, the task is in a calendar and it needs the date field, or when the task is registered from a form it is more convenient to do it from a calendar and not from a drop-down list with the 365 dates).

Do you know if there is another way using the date field instead of the relationship with a table?

Thank you very much again for your help.