Forum Discussion

DILEEPTHOMAS's avatar
DILEEPTHOMAS
Qrew Member
7 years ago

Total of a field , without relationship

I have a table in that i have one field called amount , so without any relationship how to get the total of the particular column in the same table

12 Replies

  • no can do.

    I you want to visually see a total on a report, then look at the report.  but if you need an actual field, you would need to make a dummy table just to hold the Total(s) that you want.   

    For example, new table called Sales Totals. make a single record in it. It will be [Record ID#] of 1.
    Then lock it down so no one cal add another record.

    Then on the sales table make a formula numeric field with a formula of 1.  It will calculate, not surprisingly to 1.

    Then make a relationship based on that field and make your Totals Summary field(s) and then look them up back down to the Sales table.

    There is no =SUMIF like Excel has.
  • I have done something like the following, which will require some coding though:

    1-Create a "Text-Formula" field and allow HTML tags in it
    2-Add "<img> " and have the onload() function to run a script that will run api_genResultsTable&jsa=1 query, clist for the column to be calculated and get the total in javascript. 
    3-Add "<p>" with an ID that have the record ID composed in it so you can use in it a report
    4-Return the calculated value in that <p> tag

    The only downside is that you cannot export result, it will show as script in the CSV file. But it is good to study and check visually.
    • JacobJacob's avatar
      JacobJacob
      Qrew Cadet
      Hello,

      I am trying to do something similar.  Essentially I am trying to get a summary field without a relationship.  I have some coding skills and I am proficient with quick base api's but could you possibly provide some more information on how to do this? 
    • AmmarAl-Hadeeth's avatar
      AmmarAl-Hadeeth
      Qrew Member
      Yes sir, are you familiar with the onload technique ??
      -Add a text-formula filed.
      -Allow some HTML code
      -Add "<img src='[any image url, required]' hidden onload='javascript: alert(&quot;OK&quot;)'>"
      -Try this, if it alerted "OK" then you can replace the alert function with a function that will search and calculate total using api_genResultsTable 

      Let me know if you need more clarification
    • JacobJacob's avatar
      JacobJacob
      Qrew Cadet
      Great.  I got the alert popup to work.  I am not sure how to calculate the total with the API_genresultstable?  Possible to provide some color on that as well?
  • >no can do.

    Actually you can do this naively. I really hate that word "natively" -  it is so  self-limiting.
    Expand your repertoire of skills, challenge your longstanding mindset and generally embiggen your world.
    Check out this application which introduces a new technique I call Total Recall where the table has exactly three fields:

    [Name] - Text Field
    [Amount] - Numeric Currency Field
    [Percentage] - Formula Numeric Field = 100 * [Amount] / ToNumber([Total])



    Total Recall

    https://haversineconsulting.quickbase.com/db/bnhmr8df6?a=td

    There is no image onload field being used in this application and again the table has precisely three fields: [Name], [Amount] and [Percentage].

    So how did I do it? Well the obvious question is where the field [Total] coming from? Well the simple answer is that it is not a field - it is a user defined variable whose value is calculated (via script) and set just prior to the report being displayed.

    If you move to the Tasks table you will see there is a button labeled Total.js:



    Clicking this button will execute the script in the pastie below and result in (1) calculating a new total of the [Amount] field in all records, (2) place the value in the user defined variable [Total] and (3)  redirect to the List All report:

    Pastie Database
    https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=640

    Now this may seem like a very convoluted way of generating a simple total. Why not just create a dummy or faux table to be the parent of the table holding all the data? 

    There is a very meaningful answer to this obvious question and good reason pursue solutions like this.

    When you run into a limitation on what QuickBase can do "natively" you can often achieve your overall goal by performing some type of pre-processing operation to modify the QuickBase environment by temporarily creating (a) a user defined variable or (b) a report or chart, or (c) a temporary table.

    Viewed in this more expansive light, once the pre-processing operation is complete you can then use "native" techniques to achieve some spectacular tasks (that are otherwise impossible) such as:

    • Create Custom Summary Reports
    • Create Custom Email Notifications
    • Create or Modify a QuickBase Generated Chart
    • AmmarAl-Hadeeth's avatar
      AmmarAl-Hadeeth
      Qrew Member
      The "<img> onload" technique is used to calculate the total when you load the page without having to press a button. 

      If you have a report of 50 records that the total need to be calculated for each one of them and displayed in the same row, it wouldn't be feasible to click the button 50 times! 

      Regards