Jump to content
  • 0

Getting a SUM from another related table



Thank you in advance.

I have a tabular report that I am trying to get the grand total from a related table. This is a one-to-many relationship. There are multiple records in tblB_Summary that match one record in tblProperty based on PropertyID.

tblB_Summary has a field called XBSRent that I need to get the total of all of the rents for the Property and display it in my tabular report

PropertID         PropertyName              TotalRent

1234                    Williamson Towers      $5000      <-SUM of XBSRent

XBSPropertyID           Unit#       XBSRent
1234                                  Unit 1      $1000
1234                                  Unit 2      $1000
1234                                  Unit 3      $1000
1234                                  Unit 4      $1000
1234                                  Unit 5      $1000

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Hello @Hiperf,

You may add the Calculated Field on the Tabular Report and use the following statement:

 SELECT SUM(XBSRent) FROM tblB_Summary WHERE XBSPropertyID = target.[@field:PropertID]

Please replace the names of the fields and the name of the table if needed. 

If all the values in the 'XBSRent' field are blank for some property or there are no records for that property in the 'tblB_Summary' table, this SELECT statement returns NULL(blank value).

If this scenario is possible and you need to display 0 (zero), the statement can be the following:

ISNULL(( SELECT SUM(XBSRent) FROM tblB_Summary WHERE XBSPropertyID = target.[@field:PropertID]), 0)
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...