Link to home
Start Free TrialLog in
Avatar of Steve7423
Steve7423Flag for Canada

asked on

How to calculate the Max() of a (totals) row in a Matrix report

I have a Matrix report that counts the items in columns.  The problem is that I need to then get the max() of all the (total) counted items.

Think of a spreadsheet with 30 columns and 20 rows.  Below each column there is a total which counts the number of items in the column.  See the attachement

I’ve found some possibilities using inscope and others using code behind but they all refer to the specific fields, or the max of the items within the columns and this is not what I want.

The problem is that the items in the rows (y) are actual user names and the total at the bottom of the column is a count(fields!User_Name.value).  

The problem is the Max text box must display the max from the row, eg: Max(Count(Fields!User_Name)) but you can’t do that.  

Using the attachment as the example, the Max textbox which contains Max(B12-F12)   :5 is the max of the totals.  I need to display 5 as it’s the largest within the row.
How can I find the Max of the counted values in the total textboxes.

Any and all creative approaches welcomed.
Matrix-Max-Example.bmp
Avatar of momi_sabag
momi_sabag
Flag of United States of America image

can you post here the query that generates that result?
it would be easier for me to show you how to generate that max on the query
Avatar of Steve7423

ASKER

Momi_sabag:


this is the table which the report is based on.

--CREATE TABLE tmpLicenseCount(
--ProductTag varchar(10),
--Workstationid nvarchar(50),
--Date varchar(50),
--IPAddress nvarchar(50),
--[User_Name] nvarchar(50),
--ProjectNo nvarchar(50),
--Month varchar(50),
--Year varchar(50)
--)

SELECT [ProductTag]
      ,[Workstationid]
      ,[Date]
      ,[IPAddress]
      ,[User_Name]
      ,[ProjectNo]
      ,[Month]
      ,[Year]
      ,[UserNumber]
  FROM [Manager].[dbo].[tmpLicenseCount]



I've tried using a derived table with count and Max it doesn't give me what I want.  I can't reduce the record count for the report.  If the table above contains 100 records the report must display those records, I can't reduce the records by grouping.  I'm suspecting I need two separate queries for 2 separate reports; one for the main report and a second for a report that shows the Max based on date and product code.  This second query can be reduced in records because I only need to list the Max(count()) of records per producttag and date.
Hope I haven't confused you.

SELECT
  date,
  workstationid,
  ipaddress,
  ProductTag,
  --ProjectNo,
  UserName,
  MONTH,
  year,
  Nodename,
  Max(LicenseCount) as MaxLicenses
 
  FROM (SELECT DISTINCT convert(varchar(10),LM.Date, 101) AS Date, WORKSTATIONID, LM.IPAddress, ProductTag, username, AM.MONTH, AM.year, LM.NodeName, count(lm.username) as LicenseCount FROM tbl_Magr AS AM INNER JOIN TempTableForLogs AS LM ON AM.IPAddress = LM.IPAddress
            WHERE   WorkStationID not in(select spare01 from [Manager].[dbo].[exceptions])
            and AM.UsersName not in(select username from [Manager].[dbo].[exceptions])
            GROUP BY LM.Date, AM.WorkStationID, LM.IPAddress, ProductTag, lm.UserName, AM.MONTH, AM.year, Lm.NodeName) as MaxLicenses
 
  GROUP BY Date, WorkStationID, IPAddress, ProductTag, username, MONTH, year, nodename
ASKER CERTIFIED SOLUTION
Avatar of Steve7423
Steve7423
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I would like to close the question if no one has an issue.  If anyone has a comment to add to my previous please do.  If I haven't heard from anyone in a week or so then I will close the question.
The requirements and solutions to the problem changed which altered the approach to the solution.  The solution was found outside of the report, which the original question was targeted towards.  A completly different solution was eventually found.