Sum and group by using CAML query

Is there any way to get the SUM of values with group by ID using CAML query?
I have a custom list, in that I have ID and Value columns as below
      ID         Value1      Value2
      1             10             4
      2              5              3
      1             15             2
      3             20             1
I want to get result:
     ID          Value1        Value2
     1             25                6
     2             5                  3
     3             20                1
I used CAML query:
<View>
<Query>
<Where>
<IsNotNull>
<FieldRef Name="ID" />
</IsNotNull>
</Where>
<GroupBy Collapse="FALSE">
<FieldRef Name="ID" />
</GroupBy>
</Query>
<ViewFields>
</ViewFields>
<Aggregations Value="On">
<FieldRef Name="Value1" Type="SUM" />
<FieldRef Name="Value2" Type="SUM" />
</Aggregations>
</View>
But
this query returns all the records
that satisfy the condition <Where>.
I
do not correctly?

You need to work with current view based aggregation. Please check below threads for your reference.
http://social.msdn.microsoft.com/Forums/sharepoint/en-US/dda5735a-fecf-403f-9495-1b63617d2fbf/question-on-a-caml-query?forum=sharepointdevelopmentlegacy
http://social.msdn.microsoft.com/Forums/sharepoint/en-US/24e88d6a-ee15-4d81-a5fe-504c7bd14e46/how-to-sum-a-column-value-using-caml-query?forum=sharepointdevelopment
Hope this helps.
My Blog- http://www.sharepoint-journey.com|
If a post answers your question, please click Mark As Answer on that post and Vote as Helpful
I've seen these
issues and articles and do them, but
does not work. I use object mozhel
Sharepoint (javascript).

Similar Messages

  • How to sum a column value using CAML Query?

    Hi All,
    I would like to sum the column value using CAML qeury. Actually in my list, I have two column "Projects Name" and "Number of Issues". Now need to get sum of "Number of Issues" column. How to achieve in CAML Query.
    Thanks in advance!

    Hi Sam,
    it looks like you can use your current view based agregation, otherwise it is not possible(
    http://msdn.microsoft.com/en-us/library/ms467521.aspx) and you need to work on custom bit on this requirement.
    use the below link and create a view element as described and see if that works for you
    Aggregations Element
    http://msdn.microsoft.com/en-us/library/ms468626%28v=office.12%29.aspx
    Another reference
    Query Element
    http://msdn.microsoft.com/en-us/library/ms471093.aspx
    Hope this helps!
    Ram - SharePoint Architect
    Blog - SharePointDeveloper.in
    Please vote or mark your question answered, if my reply helps you

  • How to retrieve Task Lists from All Subsites to the Parent Site and display in Grid view using CAML Query

    How to retrieve Task Lists from All Subsites to the Parent Site and display in  Grid view using CAML Query + object model

    do u just want task list or items under task list for all subsites
    for items use spsitedataquery ref
    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsitedataquery.aspx use recursive to get it from alll subsite under site collection
    for tasklist only u can a simply use a for loop to find in all subsite
    Manish Sati

  • Filter SharePoint list items using CAML query as same as Like operator in SQL Server.

    Hi ,
    I have filtered SharePoint list items based on Name using CAML query <Contains> . Now I have a new requirement is to filter list items using Like operator in SQL. But Like operator is not in CAML.
    How do I filter list items using CAML as same as Like operator in SQL.
    Please let me know.
    Thanks in Advance.

    Did you try using <Contains>?
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/15766fd5-50d5-4884-82a1-29a1d5e38610/caml-query-like-operator?forum=sharepointdevelopmentlegacy
    --Cheers

  • Retrieve All records and display in Report using CAML query in Report Builder if Parameter value is blank

    Hello Experts,
    i have created a report where i have one parameter field where user will pass parameter(e.g. EmpId). As per parameter record will fetched to report if no parameter is passed then it will display all records. I have done it by taking SqlServer Database as datasource.
    by using Following method
    Now i would like to do it by taking Sharepoint List as Datasource. For that what would be the CAML Query.
    Here is my existing CAML query.
    <RSSharePointList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <ListName>Employees</ListName>
      <ViewFields>
        <FieldRef Name="Title" />
        <FieldRef Name="FirstName" />
        <FieldRef Name="LastName" />
        <FieldRef Name="FullName" />
        <FieldRef Name="UserName" />
        <FieldRef Name="Company" />
      </ViewFields>
      <Query>
        <Where>  
    <Eq> 
        <FieldRef Name="Title" />
      <Value Type="Text">    
       <Parameter Name="EmployeeId"/>    
    </Value>
    </Eq>                  
        </Where>
      </Query>
    </RSSharePointList>
    The above code is working if i am passing an employeeId to Parameter. If nothing is passed, it is Not retrieving any record.
    Please suggest
    Thank you
    saroj
    saroj

    Your problem follows the well-established pattern of using an "All" parameter filter in SSRS. There are a few approaches depending on the size of your data. The easiest one is to return all data from CAML and then filter it within SSRS, the following thread
    provides some examples,
    http://stackoverflow.com/questions/18203317/show-all-records-some-records-based-on-parameter-value.
    Other options include passing all of the possible values within the CAML query when "All" is selected, using multiple Report Files to distinguish between both CAML queries, or to use multiple datasets with some logic to show/hide the correct one.
    Dimitri Ayrapetov (MCSE: SharePoint)

  • How to create a sub total and grand total using my query.

    How can I create a sub total for each section and grand total for using my query like this.  your help is appreciated. I am working with 9g
    WITH  BidItemsInformation  AS
    ( SELECT DISTINCT q.iplineno "Line Number", q.section "Section Number",
             i.item "Item Number",
             initcap(i.idescr) "Description" ,
             i.iunits "Unit",
             q.qty "Quantity" ,q.price  "Engineers Unit Price",
           (q.price * q.qty) "Engineers Estimate"
         FROM letprop l,
            proposal p,
            propitem q,
            bidlet b,
            bidtabs c,
            itemlist i,
            vendor v,
            bidders d 
         WHERE(l.letting = b.letting
                And b.letting = c.letting
                And p.cspecyr = i.ispecyr)
                AND q.prpitem = i.item
                AND p.contid = l.lcontid
                AND q.contid = p.contid
                AND c.vendor = l.avendor
                AND l.CALL = c.CALL
                AND q.lineflag = c.lineflag
                AND q.iplineno = c.iplineno
                AND l.letting = d.letting 
                AND c.letting = l.letting
                AND c.CALL = d.CALL
                AND v.vendor = d.vendor
                --  AND AND l.letstat = 'A'
                AND c.lineflag = 'L'
                AND  l.letting ='&letting'
                AND l.CALL = '&call'
    ), BiddersInformation  AS
    -- This is where you make your changes for vendor name and vendor number Do not touch the above code
    -- It is always the same for any call number and letting date
    ( SELECT IPLINENO "BLine Number",
            MAX(CASE WHEN VENDOR='K020'  THEN bidprice ELSE NULL END) "K020:: Unit Price",
            MAX(CASE WHEN VENDOR='K020'  THEN bidprice ELSE NULL END) K,
            MAX(CASE WHEN VENDOR='H438'  THEN bidprice ELSE NULL END) "H438:: Unit Price",
            MAX(CASE WHEN VENDOR='H438'  THEN bidprice ELSE NULL END) H,
            MAX(CASE WHEN VENDOR='U010'  THEN bidprice ELSE NULL END) "U010:: Unit Price",
            MAX(CASE WHEN VENDOR='U010'  THEN bidprice ELSE NULL END) U,
            MAX(CASE WHEN VENDOR='G110'  THEN bidprice ELSE NULL END) "G110:: Unit Price",
            MAX(CASE WHEN VENDOR='G110'  THEN bidprice ELSE NULL END) G,
            MAX(CASE WHEN VENDOR='H530'  THEN bidprice ELSE NULL END) "H530:: Unit Price",
            MAX(CASE WHEN VENDOR='H530'  THEN bidprice ELSE NULL END) H1
        FROM  BIDTABS
        WHERE LETTING='&letting'
              AND CALL='&call'
              AND BIDPRICE <> 0
        GROUP BY IPLINENO
    SELECT BidItemsInformation."Line Number",
           BidItemsInformation."Section Number",
           BidItemsInformation."Item Number",
           BidItemsInformation."Description",
           BidItemsInformation."Unit",
           BidItemsInformation."Quantity",
           BidItemsInformation."Engineers Unit Price",
           BidItemsInformation."Engineers Estimate",
           BiddersInformation."K020:: Unit Price",
            (BidItemsInformation."Quantity" * K) "KGM CONTRACTORS INC",
           BiddersInformation."H438:: Unit Price",       
            (BidItemsInformation."Quantity" * H) "HOFFMAN CONSTRUCTION COMPAN",
           BiddersInformation."U010:: Unit Price",       
            (BidItemsInformation."Quantity" * U) "ULLAND BROTHERS INC",
           BiddersInformation."G110:: Unit Price",      
            (BidItemsInformation."Quantity" * G) "GLADEN CONSTRUCTION INC",
           BiddersInformation."H530:: Unit Price",      
            (BidItemsInformation."Quantity" * H1) "HOOVER CONSTRUCTION CO"
    FROM   BidItemsInformation,BiddersInformation
    WHERE  BidItemsInformation."Line Number" = BiddersInformation."BLine Number";
    Line Number     Section Number     Item Number     Description     Unit     Quantity     Engineers Unit Price     Engineers Estimate     K020:: Unit Price     
    0010     0001     2011601/00003     Construction Surveying     LS       1     143,000     143,000     75,000     75,000     67,080     67,080
    0013     0001     2013601/00010     Survey Equipment     LS       1     25,000     25,000     25,000     25,000     30,000     30,000
    0020     0001     2015601/00030     Blast Monitor/Survey     LS       1     50,000     50,000     30,000     30,000     35,000     35,000
    0030     0001     2021501/00010     Mobilization     LS       1     382,250     382,250     809,000     809,000     704,000     704,000
    0040     0001     2021602/00010     Well Survey     EACH     60     500     30,000     2,150     129,000     1,600     96,000
    0050     0001     2031501/00040     Field Office Type D     EACH     1     6,367     6,367     4,000     4,000     25,000     25,000
    sub total:
    1610     0002     2401501/01143     Structural Concrete (1a43)     C Y      46     350     16,100     408     18,768     400     18,400
    1620     0002     2401501/01362     Structural Concrete (1c62)     C Y      68     200     13,600     204     13,872     200     13,600
    1630     0002     2401501/03643     Structural Concrete (3y43)     C Y      60     600     36,000     592     35,520     580     34,800
    1640     0002     2401512/03633     Bridge Slab Concrete (3y33)     S F      1,876     24     45,024     28     51,778     27     50,652
    1650     0002     2401521/00030     Structure Excavation Class R     C Y      17     125     2,125     1,000     17,000     500     8,500
    1660     0002     2401541/00010     Reinforcement Bars     LB       2,490     2     3,735     1     3,312     1     3,237
    1670     0002     2401541/00011     Reinforcement Bars (Epoxy Coated)     LB       12,380     2     18,570     1     17,703     1     17,332
    1680     0002     2401601/00010     Structure Excavation     LS       1     2,500     2,500     2,000     2,000     5,000     5,000
    1690     0002     2402583/00020     Ornamental Metal Railing Type Special     L F      284     150     42,600     194     55,096     190     53,960
    sub total
    1820     0003     2401513/00346     Type Curb Railing Concrete (3y46)     L F      135     25     3,375     16     2,093     15     2,025
    1830     0003     2401513/07447     Type Mod P-4 (Tl-4) Railing Conc (3y46)     L F      302     85     25,670     72     21,593     70     21,140
    1840     0003     2401541/00010     Reinforcement Bars     LB       14,780     1     18,475     1     13,598     1     13,302
    1850     0003     2401541/00011     Reinforcement Bars (Epoxy Coated)     LB       76,720     1     103,572     1     85,926     1     84,392
    1860     0003     2401601/00010     Structure Excavation     LS       1     10,000     10,000     116,000     116,000     115,000     115,000
    1870     0003     2402583/00020     Ornamental Metal Railing Type Special     L F      132     150     19,800     184     24,288     180     23,760
    sub total
    total

    You can accomplish that using decode with the grouping function. It returns 1 when that column passed as argument was grouped (or is in some total) and 0 otherwise.
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> with t as
      2  (select 'New York' city, 'US' country, 1 num from dual
      3  union all select 'Los Angeles' city, 'US' country, 2 num from dual
      4  union all select 'London' city, 'GB' country, 2 num from dual
      5  union all select 'London' city, 'GB' country, 2 num from dual
      6  union all select 'London' city, 'GB' country, 7 num from dual)
      7  select decode(grouping(country), 0, country, 'GRAND TOTAL') country,
      8         decode(grouping(city), 0, city, decode(grouping(country), 0, 'SUBTOTAL')) city,
      9         sum(num) num_total
    10   from t
    11  group by rollup(country, city)
    12  /
    COUNTRY     CITY         NUM_TOTAL
    GB          London              11
    GB          SUBTOTAL            11
    US          New York             1
    US          Los Angeles          2
    US          SUBTOTAL             3
    GRAND TOTAL                     14
    6 linhas selecionadas.
    SQL>

  • Join two list with condition using caml query in SharePoint 2013 with client object model

    Hi,
    Want to join two list to get all fields from both list.
    Am new to sharepoint and sharepoint 2013. Am working in sharepoint 2013 online apps. Am using context.executeQueryasync to load list and get items from list. Am able to get items from single list with caml query, but not able to get both list field values
    with joins.  I did lot of surfing..but not..
    Below is my code..
    ListName1 : "AssignedTasks"
    ListName2 : "Tasks"
     var assignedQueryTest = "<View><Joins><Join Type='INNER' ListAlias='Tasks'><Eq><FieldRef Name='TaskId' RefType='Id'/><FieldRef List='Tasks' Name='ID' /></Eq></Join></Joins>"
                    + "<ViewFields><FieldRef Name='TitleValue' /><FieldRef Name='ActionItemsValue' /></ViewFields>"
                    + "<ProjectedFields>"
                    + "<Field Name='TitleValue' Type='Lookup' List='Tasks' ShowField='Title' /><Field Name='ActionItemsValue' Type='Lookup' List='Tasks' ShowField='ActionItems' />"
                    + "</ProjectedFields>"
                    + "</View>";
                   var web = context.get_web();
                    var list = web.get_lists().getByTitle("AssingedTasks");
                    var myQuery = new SP.CamlQuery();
                    myQuery.set_viewXml(assignedQueryTest);
                    var myItems = list.getItems(myQuery, "Include(TitleValue,ActionItemsValue)");
                    context.load(myItems);
                    context.executeQueryAsync(function () { if(myItems.get_count()>0){....}
    }, errorCallback);
    Here am able to get "AssignedTasks" list field values but not able to get "Tasks" list field values. 
    Can you please help me to resolve the issue. Or new idea for join. I have add the condition also in the query.
    If anybody have good sample, please provide.
    Thanks,
    Pariventhan
    Pariventhan.S

    Hi Pariventhan,
    I don't know about join but I have a workaround of this problem.
    Declare one variable (itemcollection) globally. Load all the items "AssignedTasks" using context.load.
    In the success method call another CAML query using <IN> tag of the ID of the items from the second list (Assuming you have look-up column of the ID of the first list to the second list).
    If this is not clear to you then please let me know. If possible then I can provide code sample.
    Thanks,
    Aniruddha

  • Join two list of integer type field using CAML query

    Hi
    As i am struggling in Join two sharepoint list (Roles and Emplyees). As there is no lookup columns and lists are already existing and have almost 3000 + recodrs. As a part of enhancement work need to join these list. List structure is some thing as follows: 
    Roles :
    ID                              Title
    1                               Project Manager
    2                               Business Analyst
    3                              Developer
    Employees :
    Name                       Role
    1 James                  1
    2 Petar                    3
    3 John                     2
    Output should be like as follows:
    Name                       Role
    1 James                  Project Manager
    2 Petar                    Developer
    3 John                     Developer
    So please suggest, if the joining can be done other than lookup columns through the CAML query.
    Akhilesh Rao

    Follow below CAML query to add joins between two lists.
    SPList list = SPContext.Current.Site.RootWeb.Lists["Employees"];
    SPQuery query = new SPQuery();
    query.Joins = @" <Join Type="INNER" ListAlias="Roles">
    <Eq>
    <FieldRef Name="Employees" RefType="Role" />
    <FieldRef List="Roles" Name="ID" />
    </Eq>
    </Join>";
    query.ProjectedFields = @" <Field Name="RoleName" Type="Lookup" List="Roles" ShowField="Title">";
    query.ViewFields = @ "<FieldRef Name="Title">
    <FieldRef Name="RoleName"> ";
    SPListItemCollection result = tablea.GetItems(query);
    Adnan Amin MCT, SharePoint Architect | If you find this post useful kindly please mark it as an answer :)

  • Count of items ina list using CAML Query

    Hi,
    Thanks in Advance
    I'm using an app called blumshapiro to customize the tile in sharepoint 2013, I also have a requirement of getting the item count from the list which can be done by writing a CAML Query. Can anyone please assist me with the syntax to fetch the item count
    in caml Query.
    Regards,
    Niranjan

    Hi 
    There is nothing like item count in Camel query.You can get Required result using SPListItemCollection.Count
    Do a normal where clause having condition.
    SPQuery query = new SPQuery();
    string camlquery = @"<Query>
    <Where>
    <Eq>
    <FieldRef Name='Vendor_x0020_Product_x0020_Name'/>
    <Value Type='Text'>" + xpathresultBTADSLMAX + @"</Value>
    </Eq>
    </Where>
    </Query>";
    query.Query = camlquery;
    SPListItemCollection listItemCollection = list.GetItems(query);int count=0;if(listItemCollection !=null) { count=ListItemCollection.Count}MSDN reference
    http://msdn.microsoft.com/en-us/library/ms467521.aspx
    Regards, Rajendra Singh If a post answers your question, please click Mark As Answer on that ost and Vote as Helpful http://sharepointundefind.wordpress.com/

  • How to update a People and group field using a sandbox solution

    Hi,
    I am creating a sandbox solution for office 365 and creating a custom form using visual web part, which will allow users to enter data in a custom list.
    And that list also have a user field. I am able to get SharePoint user field on the form (using javascript) which is searching for the user and get a value (working fine).
    Issue: But I am not able to save the user value. Because to save user value I require web, UserID and login name, to construct SPFieldUserValue object or string in "111;#TestUser" format. Moreover that user should be present in
    SiteUserInfoList. 
    I tried web.EnsureUser() but did not work under sanbox solution.
    Can you please provide any pointer or workaround to the problem? I may be missing something here.
    Thanks,
    Himanshu

    Hi,
    According to your description, my understanding is that you want to update the people and group field in Sandbox solution.
    In the sandbox solution, you can still use the web.EnsureUser() function to get the user information, see the thread below:
    EnsureUser in sandboxed solution
    In additional, there is a demo with your similiar requirement for your reference:
    Using the People Picker Control in Sandbox Solutions / Office 365
    Thanks
    Best Regards,
    Jerry Guo
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Using CAML Query in SharePoint Hosted app

    Hi,
    I am trying to execute a CAML Query in a SharePoint Hosted App, below is the JS code.
        executor.executeAsync({
            url: appwebUrl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('Documents')/Items?/getitems?@target='" + hostweburl + "'",
            method: "POST",
        body: { 'query' : {'__metadata': { 'type': 'SP.CamlQuery' }, "ViewXml": "<View><Query><Where><Eq><FieldRef Name='Title'/><Value Type='TEXT'>value</Value></Eq></Where></Query></View>"
        headers: {
            "accept": "application/json; odata=verbose",
            "content-type": "application/json; odata=verbose"
        success: successHandler,
        error: errorHandler
    getting an error: Uncaught Error: "Invalid field or parameter requestInfo.body"

    Are you using rest api?
    Please check this
    http://tech.bool.se/using-caml-sharepoint-rest-api/
    http://msdn.microsoft.com/en-us/library/office/dn531433(v=office.15).aspx

  • To get list of Structure, CKF and RKF where used in query

    Hi All,
    We are going to migrate the queries from BW.3.5 to BI 7.0.
    Our aim  is to get list of Structure, CKF and RKF that are being used in the Info provider along with Queries of these Structure ,RKF's and CKF' s .Is there any way
    to get the where used in query.
    Thanks,
    Mohan

    It's been discussed so many times: Check these forums>>
    http://scn.sap.com/thread/2029042
    BEx metadata tables - how to list Query/Chars/KFs
    Rgds..
    Shambhu

  • How do I know which group and group counter used to create current estimate

    Is there a way to know, if for a given set of materials, what groups and groups counters have been used to create the current cost estimate. Or for a given comboniation of material, group and group counter has been used to create a current cost estimate. I can look each up through displaying the cost estimate but I am looking for a quick way since the number of materials are in 100s.
    I was wondering if there is a table I could look up to get the info.
    Any help would be much appreciated.
    Regards

    The name of the table that needs to be used is KEKO. I figured it out so I thought I would share
    Edited by: NIK83 on Mar 7, 2011 10:16 PM

  • Hoe top create summary and detail report using ABAP QUERY

    Hi ,
    Can any one suggest me how to create summary and detailed report using ABAP Quey.
    Regards,
    Raghu.

    Hi,
    Table Declaration
    tables:mara,mast.
    *Declaring the internal table
    data: begin of itab_new occurs 0,
          matnr like mara-matnr,     "Material No
          ernam like mara-ernam,     "Material Created by
          mtart like mara-mtart,     "Material Type
          matkl like mara-matkl,     "Material Desc
          werks like mast-werks,     "Plant
          aenam like mast-aenam,     "BOM created
          stlal like mast-stlal,     "Alternative BOM
          end of itab_new.
    select-options: p_matnr for mara-matnr.
    CODE A : Retrieving the data from the database
         select  f~matnr f~ernam f~mtart f~matkl m~werks m~aenam m~stlal
         into table itab_new
         from mara as f inner join mast as m
         on f~matnr = m~matnr
         where f~matnr in p_matnr.
    CODE B : Retrieving the data from the database.
        SELECT FMATNR FERNAM FMTART FMATKL MWERKS MAENAM M~STLAL
        INTO TABLE ITAB_NEW
        FROM MARA AS F INNER JOIN MAST AS M
        ON FMATNR = MMATNR
        WHERE F~MATNR = P_MATNR.
        SORT ITAB_NEW BY ERNAM.
    loop at itab_new.
    write:/5  itab_new-matnr,itab_new-ernam,itab_new-mtart,itab_new-matkl,itab_new-werks,itab_new-aenam,itab_new-stlal.
    endloop.
    *TABLES: MARA , MAST.
    *DATA:BEGIN OF ITAB_NEW OCCURS 0,
                 MATNR LIKE MARA-MATNR,
                 ERNAM LIKE MARA-ERNAM,
                 MTART LIKE MARA-MTART,
                 MATKL LIKE MARA-MATKL,
                 END OF ITAB_NEW.
       SELECT MATNR ERNAM MTART MATKL
       INTO TABLE ITAB_NEW
       FROM MARA
       WHERE MTART = 'T'
       ORDER BY MATNR ERNAM MTART MATKL.
    *DATA: BEGIN OF ITAB OCCURS 0,
         MATNR LIKE MARA-MATNR,
         END OF ITAB.
    Thank U,
    Jay....

  • SQL SUM and Group By Function Wrong Result

    Hi All,
    I have a SQL view with all the payment transaction for a property per month and trying to sum all the transactions per month per property. For some months the total is not correct. For example for property 3856, in Jan 2014, the total should come to
    728 but the query lists 2184.
    Trans Date
              Amount
    Prop Code
    31/1/2014
    728          
    3856   
    31/1/2014
    -2184         
    3856   
    31/1/2014
    2184         
    3856   
    Output Required
    Year      Month   Amount     Prop Code
    2014        1          728              3856
    My Query
    Select [Prop Code], year(ttp.[Trans Date]) AS [Year], Month(ttp.[Trans Date]) AS [Month], SUM(ttp.[Payment Amount]) as Total
    FROM vw_tenant_payments as ttp
    GROUP BY [Prop Code], year(ttp.[Trans Date]), Month(ttp.[Trans Date])

    Hi All,
    I got it, it skipped my mind to restrict the payment type to RENT as even the deposit is in the transaction view
    Select
    [Prop Code],year(ttp.[Trans
    Date])AS[Year],Month(ttp.[Trans
    Date])AS[Month],SUM(ttp.[Payment
    Amount])asTotal
    FROM
    vw_tenant_payments
    asttp
    Where
    [Account Code]
    ='RENT'and[Prop
    Code] ='3856'
    GROUP
    BY[Prop
    Code],year(ttp.[Trans
    Date]),Month(ttp.[Trans
    Date])
    Order
    by[Prop
    Code],[Month]

Maybe you are looking for