Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7816757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:59:06+00:00 2026-06-02T05:59:06+00:00

I have a table like this in the report designer: Category: 1 2 3

  • 0

I have a table like this in the report designer:

Category:       1     2       3      4   Total
Max Amount:     x     y       z      c     ?

I need to get the total of Max Amount, but expressions will not let me take Sum(Max(amount)), and the add total is disabled for this cell.

The max amount row is an expression that takes the max of each category. The source data has repeated values, so I just take the max. For example:

Category    Amount
    1         4.6
    1         4.6
    1         4.6
    2          5
    3          4

Other columns in the table are different, but amount will be the same so I cannot only select distinct values.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T05:59:08+00:00Added an answer on June 2, 2026 at 5:59 am

    Maybe something like this:

    SELECT
        SUM(t1.maxAmout)
    FROM
    (
        SELECT
            MAX(t.Amout) AS maxAmout,
            t.Category
        FROM
            yourTable AS t
        GROUP BY
            t.Category
    ) AS t1
    

    You can also do it like this. If you are using sql server 2005+:

    SELECT
        pvt.[1],
        pvt.[2],
        pvt.[3],
        (
            pvt.[1]+
            pvt.[2]+
            pvt.[3]
        ) AS Total
    FROM
    (
        SELECT
            t.Category,
            t.Amout
        FROM
            yourTable AS t
    ) AS SourceTable
    PIVOT
    (
        MAX(Amout)
        FOR Category IN([1],[2],[3])
    ) AS pvt
    

    EDIT

    If you have a 1000 categories. Then a dynamic pivot would be the best solution. So like this:

    Test data

    CREATE TABLE #T
        (
            Category INT,
            Amout FLOAT
        )
    
    INSERT INTO #T
    VALUES
        (1,4.6),
        (1,4.6),
        (1,4.6),
        (2,5),
        (3,4)
    

    Unique column names

    DECLARE @cols VARCHAR(MAX)
    DECLARE @colsTotal VARCHAR(MAX)
    ;WITH CTE
    AS
    (
        SELECT
            ROW_NUMBER() OVER(PARTITION BY t.Category ORDER BY t.Amout) AS RowNbr,
            t.*
        FROM
            #T AS t
    )
    SELECT  @cols = COALESCE(@cols + ','+QUOTENAME(Category),
                         QUOTENAME(Category)),
            @colsTotal=COALESCE(@colsTotal + '+ISNULL('+QUOTENAME(Category)+',0)',
                         'ISNULL('+QUOTENAME(Category)+',0)')
    FROM 
        CTE
    WHERE
        CTE.RowNbr=1
    ORDER BY 
        Category
    

    Dynamic pivot

    DECLARE @query NVARCHAR(4000)=
    N'SELECT
        '+@cols+',
        (
            '+@colsTotal+'
        ) AS Total
    FROM
    (
        SELECT
            t.Category,
            t.Amout
        FROM
            #T AS t
    ) AS SourceTable
    PIVOT
    (
        MAX(Amout)
        FOR Category IN('+@cols+')
    ) AS pvt'
    
    EXECUTE(@query)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have mysql table with data like this. record will have server with total
I have table like this: +----+---------+---------+--------+ | id | value_x | created | amount
i have a table report like this YYYYMM pipno demand principle interest balance=(demand-principle) 201010
I have table like this : ID Name_1 Name_2 Name_3 1 Egon Spengler Ives
I have a table like this: Application,Program,UsedObject It can have data like this: A,P1,ZZ
I have a Table like this one: |UserId | ContactID | ContactName --------------------------------------- |
I have a table like this: name code group john 12 smith 15 how
I have a table like this... CustomerID DBColumnName Data 1 FirstName Joe 1 MiddleName
i have a table like this one: -------------------------------- id | name -------------------------------- 1 |
I have two table like this table_CN (_id, name, phone, favorite, title) table_EN (_id,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.