Microsoft Access - grand total adding multiple fields together - ms-access

I can't quite figure this out. Microsoft Access 2000, on the report total section I have totals for three columns that are just numbers. These =Sum[(ThisColumn1)], 2, 3, etc and those grand totls all work fine.
I want to have another column that says =Sum([ThisColumn1])+Sum([ThisColumn2]) + Sum([ThisColumn3]) but can't figure those one out. Just get a blank so I am sure there is an error.

Give the 3 Grand Totals meaningful Control Names and then for the Grand Grand Total use:
=[GrandTotal1] + [GrandTotal2] + [GrandTotal3]
Your Grand Total formulas should be something like:
=Sum(Nz([ThisColumn1], 0))

NULL values propagate through an expression which means that if any of your three subtotals are blank, the final total will also be blank. For example:
NULL + 10 = NULL
Access has a built in function that you can use to convert NULL values to zero.
NZ( FieldName, ValueIfNull )
You can use NZ in reports, queries, forms and VBA.
So the example above could read like this:
=NZ([GrandTotal1],0) + NZ([GrandTotal2],0) + NZ([GrandTotal3],0)
http://office.microsoft.com/en-us/access/HA012288901033.aspx

Create a new query, and the sql should look like this:
SELECT SUM(Column1 + Column2 + Column3),
SUM(Column1),
SUM(Column2),
SUM(Column3),
FROM Your_Table;

Related

Select a value using iif access query

I have a row who contains this value :
account :
adm.ahrgrst001
adm.ns2dhdujhd
adm.ff2hdjhh
adm.haidhidh103
adm.hshiksh122
adm.cn3ehuioe
i want to extract two different values:
when it ends like adm.hshiksh122 i want to extract hshiksh
and with start with adm.cn3ehuioe i want ehuioe
both without the adm. at the beginning
I have thinked this
IIF(isnumeric(RIGHT (account,3)),LEFT(account,LEN(account)-4),RIGHT (account,LEN(account)-7))
the value that are like adm.cn3ehuioe i got wrong like adm.cn3ehui
and adm.ahrgrst001 is correct ahrgrst
Thanks to everyone who will read
The correct way to get the 2 types of values is with:
account LIKE 'adm.[!0-9][!0-9]#[!0-9]*'
for the values that have 2 letters, 1 digit and letters after the dot, and:
account LIKE 'adm.*###'
for the values that end in 3 digits.
So use this:
SELECT IIF(
account LIKE 'adm.*###' ,
MID(account, 5, LEN(account) - 7),
MID(account, 8)
) AS result
FROM tablename
WHERE account LIKE 'adm.*###' OR account LIKE 'adm.[!0-9][!0-9]#[!0-9]*'
If there are no other values than these 2 types then you may remove the WHERE clause.
Results for your sample data:
result
ahrgrst
dhdujhd
hdjhh
haidhidh
hshiksh
ehuioe

Using like operator in SSRS Expression

I have a tablix with following results.
SSRS Result
Since i am learning SSRS. i wonder how to Sum line total with respect to product name. Since product name has duplicate values but it has only M and Xl difference. If i use row group it won't total like i expected since it has M and Xl difference. I wonder how to write an expression for the total.
The desired result set
May 31 2011 S043659 Long-Sleeve Logo jerse M 3 $86.52
Long-Sleeve Logo jersey XL 1 $28.84
Total $115.36
mountain bike socks M 6 $34.20
i used this expression but giving me an error.
`IIF((Fields!Product.value = Previous(Fields!Product.value),Sum(Fields!linetotal.value))`
There's actually a few things wrong with your expression.
The IIF doesn't have a 3rd argument for the ELSE value. In this case, you'd want to use 0. So the expression would be IIF the fields match then LineTotal Else 0.
You want to have the SUM on the outside of the IIF, otherwise it will only SUM one row.
The matching without the size is trickier. I have it trim off the last 4 characters to exclude the size for a match - it may not work depending on your other Product names.
=SUM(IIF(LEFT(Fields!Product.value, LEN(Fields!Product.value) - 4) = LEFT(Previous(Fields!Product.value), LEN(Fields!Product.value) - 4), Fields!linetotal.value, 0))
The expression reads the SUM of (IF the Product matches the Previous Product then the Line Total else 0).
All this being said, it would actually be easy to crate a parent group and GROUP BY on the parent product. Unfortunately, your data uses a comma to separate one type (jersey) by size but a space in another (socks) so I don't see how to do it. If they all had a comma, I would create a Calculated Field on the dataset to use the product-line up to the comma.
=LEFT(Fields!Product.value, INSTR(Fields!Product.value, ",") - 1)
IF your Product line is either a comma or space to separate, you might be able to use this for your Calculated Field:
=LEFT(Fields!Product.value,
IIF(INSTR(Fields!Product.value, ",") > 0,
INSTR(Fields!Product.value, ",") - 1,
InStrRev(Fields!Product.value, " ") - 1) )

How to get the total right result in my report for entered calls?

I have report with entered calls.I want to get the total sum of my column %Weekdays.
For example i will show you my values and the expected result:
The expected result is 100,7%
https://imgur.com/blCWR5A
This is my code for %weekdays ( average values ) , but i want total values from all rows:
=avg(IIF(Weekday(Fields!DATE_YYYYMMDD.Value,2)<6,CDBL(Fields!N_ENTERED.Value),Nothing))/
iif(Sum(IIF(Weekday(Fields!DATE_YYYYMMDD.Value,2)<6, CDBL(Fields!N_ENTERED.Value), Nothing),"PRESENTATION_NAME")=0,1
(Sum(IIF(Weekday(Fields!DATE_YYYYMMDD.Value,2)<6, CDBL(Fields!N_ENTERED.Value), Nothing),"PRESENTATION_NAME")/
iif(code.getWeekDaysCount(Parameters!From_date.Value,Parameters!To_date.Value)=0,1,code.getWeekDaysCount(Parameters!From_date.Value, Parameters!To_date.Value))))
If you just want to sum the "% weekdays" column, assuming it's called myWeekdaysCol then you can just do
=SUM(ReportItems!myWeekdaysCol.Value)
The will simply sum the final result without having to create a long, hard to read expression.
Here is what I simplified your data and have generated sum of it
%weekday is just =Fields!Weekday.Value/10.40
Then I just created outside Group-below for Sum of %weekday
and to generate sum it simply just
=Sum(Fields!Weekday.Value/10.40)
In my oversimplified case I generate &weekday with divide by 10.40 this is my formula.
You will have to do something like below
=Sum(avg(IIF(Weekday(Fields!DATE_YYYYMMDD.Value,2)<6,CDBL(Fields!N_ENTERED.Value),Nothing))/
iif(Sum(IIF(Weekday(Fields!DATE_YYYYMMDD.Value,2)<6, CDBL(Fields!N_ENTERED.Value), Nothing),"PRESENTATION_NAME")=0,1
(Sum(IIF(Weekday(Fields!DATE_YYYYMMDD.Value,2)<6, CDBL(Fields!N_ENTERED.Value), Nothing),"PRESENTATION_NAME")/
iif(code.getWeekDaysCount(Parameters!From_date.Value,Parameters!To_date.Value)=0,1,code.getWeekDaysCount(Parameters!From_date.Value, Parameters!To_date.Value)))))

Get value between from to dataset columns ssrs

I have a data set like that:
Data Set Contents
From To Comment
----+---+--------
0 50 Bad
50 70 Good
70 100 Excellent
If I have a value of 75, I need to get Excellent by searching the Dataset.
I know about the lookup function but it is not what I want. How can I do that?
The values should be in percentage.
Note : the value (75) is Average of a column (Calculated) it
calculate student grade from max and student mark Version SQL Server
2016
Note 2 : the dataset is from database not static values
Thank You
Assuming you only ever have a fixed number of 'grades' then this will work. However, I would strongly recommend doing this type of work on the server where possible.
Here we go...
I created two datasets
dsGradeRange with the following sql to recreate your example (more or less)
DECLARE #t TABLE (low int, high int, comment varchar(20))
INSERT INTO #t VALUES
(0,49,'Bad'),
(50,69,'Good'),
(70,100, 'Excellent')
SELECT * FROM #t
dsRandomNumbers This just creates 30 random numbers between 0 and 100
SELECT *
FROM (SELECT top 30 ABS(CHECKSUM(NEWID()) % 100) as myNumber FROM sys.objects) x
ORDER BY myNumber
I added a table to the report to show the grades (just for reference).
I then added a table to show the dsRandomNumbers
Finally I set the expression of the 2nd column to the following expression.
=SWITCH
(
Fields!myNumber.Value < LOOKUP("Bad", Fields!comment.Value, Fields!high.Value, "dsGradeRange"), "Bad",
Fields!myNumber.Value < LOOKUP("Good", Fields!comment.Value, Fields!high.Value, "dsGradeRange"), "Good",
True, "Excellent"
)
This gives the following results
As you can see we only need to compare to the high value of each case, the first match will return the correct comment.
Right click on your dataset and add a calculated field. Go to Field Properties > Fields > Add and add the following expression, which descripes your scenario:
=IIF(Fields!Number.Value < 50, "Bad", "Good")

How to create a computed column name using another column's value (sql server 2008)

I need to use the value of a column in the name of a new column....this is the line I need help with:
Count([DepartmentName]) As [[DepartmentName] + "Emails"]
Code:
SELECT
[CustomerId],
#MetricMonth AS "MetricMonth",
#MetricYear AS "MetricYear",
[LeadType], [DeviceTypeId], [DepartmentName],
Count([DepartmentName]) As [[DepartmentName] + "Emails"]
FROM
[myTable]
WHERE
LeadType = #LeadType
AND _CreateDate BETWEEN #StartDateTime AND #EndDateTime
GROUP BY
[CustomerId], [LeadType], [DeviceTypeId], [DepartmentName]
The reason for the need is that the receiving table has columns labeled as such and this seems like the cleanest way to do it. There are 16 possible values for DepartmentName so I don't want to have a bunch of case statements.
Here's a sample of the result. There will be multiple groups because of DepartmentName and DeviceTypeId.
CustomerId MetricMonth MetricYear LeadType DeviceTypeId DepartmentName NewName
28590 4 2014 Email 1 New 9
36980 4 2014 Email 1 Finance 3
876 4 2014 Email 1 New 9
Thanks!
You in effect want a column name that has multiple values, ie a column with multiple names, which is just impossible in any flavor of SQL, afaik.
Short of that, you have two options:
if you really want columns with names like "Department1 Emails" then you will have to pivot the data (and you'll have to hard-code all the Department Names). If that is what you want see here.
if you just want a column called "Department Emails" with values such as "Department1 Emails: 30" then you can do this:
SELECT [DepartmentName], [DepartmentName] + ' Emails: ' + CAST(COUNT([DepartmentName]) AS VARCHAR(20))
FROM [myTable]
GROUP BY [DepartmentName]