Include a customized calculated field in MS Access Query - ms-access

I am trying to execute a calculated field in MS Access.
Background
I have a single table including fields such as:
Name Week Hours_Charged
X 21-06 10
Y 21-06 20
X 21-06 30
Z 21-06 40
I am trying to create a new field in the query wherein it says Gap and contains the substraction from 40.
Additionally, it will should group according to the Same names. So the expected output would be:
Name Week Hours_Charged Gap
X 21-06 40 0
Y 21-06 20 -20
Z 21-06 40 0
Conditions: With the same name, there can be various dates and hours. However, the idea remains same.
Any leads on this would be appreciated.
Thanks in advance.
I have tried implementing through the design mode but was not successful.

I replied your table like this:
And got this query:
SQL code of this query (please note I've used different field names):
SELECT Table1.MyName, Table1.MyWeek, Sum(Table1.Hours_Charged) AS SumaDeHours_Charged, 40-[SumaDeHours_Charged] AS GAP
FROM Table1
GROUP BY Table1.MyName, Table1.MyWeek;
And design view of this query in MS Access (Please, note my Access is in spanish, so name of rows in design view are in spanish, not in english. If you want to know the meaning of something, you can ask me or use the SQL code:

Related

SumIIF Access Query

I am struggling to get the desired results i need using an Access query, and was wondering if what i was looking to do was actually achievable in one query, or whether i would need two queries and then export to Excel and interrogate the results there.
I've a table with a number of columns, i am specifically looking at three columns
Row Type - this will either be populated with A or U
Account Number - there will be potentially multiple instances of account number within the table. Although only once against row type "A", and multiple on row type "U"
Value - a currency field. At Account number level, the sum of "U" row, should equal the "A" value
I am looking to produce a query that will list three things.
[Account Number]
Sum of [Value] when [RowType] = "U"
[Value] when [RowType] = "A"
Would i need to create a new column in my table to generate a value for the requirement "Sum of Value when 'U')
I've tried
SUM(IIF([ROWTYPE]='U',[Value],0)) - but that doesn't seem to work.
I've also tried to use the builder within the Query to replicate the same, but again that also doesn't seem to work.
If all else fails i'm content to have to run two queries in Access and then join Excel, but i tihnk for my own learning and knowledge it would be good to know if what i am trying to do is possible.
I was hoping this is possible to compile in Access, but my knowledge of the application is seriously lacking, and despite looking on the MS Access support pages, and also some of the response on the StackOverflow forums, i still can't get my head around what i need to do.
Example of the data
Row Type
Account ID
Value
A
123456789
50.00
U
123456789
30.00
U
123456789
20.00
A
987654321
100.00
U
987654321
80.00
U
987654321
20.00
The data has been loaded into Access, table called "TEST"
This is the SQL i've got, but doesn't give me the desired results.
SELECT [TEST].[ROW TYPE], SUM([TEST].[VALUE]) AS [TEST].[ACCOUNT ID]
FROM [TEST]
GROUP BY [TEST].[ROW TYPE], [TEST].[ACCOUNTID]
When the query generates, would hope to see two rows, one for each account number.
Three row -
Account Number
Sum Value (where row is U)
Value (Where row is A)
I currently get 4 rows in the query. Two results for each account number, one result is the Value when Row Type = A, the other when Row Type = U.
I guess this is what you are after:
SELECT
[Account ID],
Sum(IIf([Row Type]="A",[Value],0)) AS A,
Sum(IIf([Row Type]="U",[Value],0)) AS U
FROM
TEST
GROUP BY
[Account ID];
Output:
Account ID
A
U
123456789
50,00
50,00
987654321
100,00
100,00

How to take % value for Line graph for series Groups ?/How to plot graph by sql table?

Approach 1:How to take % value for Line graph for series Groups?
I am setting up a ssrs report like with x axis(Category Group) as Finished Week, QualityPercent( as Series groups-RFT%,REwork%,Scrap%) and Values as Sum of Quantity.
In the above graph the quatities are shown in percentages based upon weeks(the actual result whose plot values are given at left side of image). Respective tables structure:
But I am getting the chart like this
Here the y axis is not plotting well asper the category values, sometimes shoots upto 250%!! or 1400% !!! (this is embarrassing).
For the above graph i used expression as:
IIF(Sum(Fields!QTY.Value,"Chart11_SeriesGroup"),Sum(Fields!QTY.Value)/Sum(Fields!QTY.Value, "DataSet_Production"),0)
What i am missing? I even used #Percent. Kindly help me.
Approach 2: How to plot the ssrs graph using below result from sql query?
FinishedWeek QualityPercent QTY Percentage
1 Rework (%) 844 0.109724
1 RFT (%) 6811 0.885465
1 Scrap (%) 37 0.004810
2 Rework (%) 742 0.094618
2 RFT (%) 7096 0.904871
2 Scrap (%) 4 0.000510
After much work done with second approach, I wrote the separate query for the above table
asper the link:
Calculating percentage within a group
select t1.FinishedWeek,t1.QualityPercent,Sum(QTY) as QTY,Sum(QTY)/ t2.TOTAL_QTY as Percentage from #temp
AS t1
JOIN (
select FinishedWeek,Sum(QTY) as TOTAL_QTY from #temp
group by FinishedWeek
) AS t2
ON t1.FinishedWeek= t2.FinishedWeek
group by t1.FinishedWeek,QualityPercent,t2.TOTAL_QTY
From above query , took the Finished Week as Category, QTY as Values, and QualityPercent as Series Groups

SSRS histogram adding extra data. (chart)

I am trying to create a histogram to show frequency distribution using the following data in a table.
Values 25 35 37 37 38 38 40 40 41 44 46
For some reason an extra value of 45 is being added to my chart.
I have stripped this down to my query being something like this and have placed my dataset into a table to see the data and the correct data is being pulled.
SELECT values FROM table
So my problem is that I have 11 pieces of data but 12 are being displayed. What may be missing here?
This isn't using the histogram properties of the series but it should give you what you want.
I created a test dataset as follows
CREATE TABLE #t (score int)
INSERT INTO #t VALUES (25),(35),(37),(37),(38),(38),(40),(40),(41),(44),(46)
SELECT score, count(*) as Freq
FROM #t
GROUP BY Score
The obvious change is the frequency is calculated in the dataset query this time.
I then added a normal column chart, set the category groups to group on score and the values as [Sum(Freq)]
I then changed the Horizontal Axis properties as follows:
Axis Type = Scalar (Numbers/Dates)
Axis Range Interval = 1
Here's a link to the RDL, it contains your version and this new version. I've not added data labels etc. but hopefully it'll be helpful.
Histogram RDL

how to find the number ranges in a set of numbers in access

i read the article Finding continuous ranges in a set of numbers but how to display it in a query in MS access as a summary for example :- if i have a set of numbers with continuous ranges 73780 to 73850 and 74000 to 74150 and etc.....and if the numbers from 73851 to 73999 are missing , i want to display only the number ranges present in my set of numbers in a tables as follows 73780 -73850 and 74000-74150 are present.i don t need the missing numbers.i just want the continuous ranges present in the set of numbers in a specific column of my table .please help me.. i search in the web.but i could not find a answer suitable for me to do with it MS Access
|number ranges present|
| 73780 - 73850 |
| 74000 - 74150 |
That's a clever method in the link.
So write the records ordered to a table with an AutoNumber, update field Diff, and use this query:
Select Min(Number), Max(Number)
From NumberTable
Group By Diff

FileMaker - Total SubSummary Values

I have a table with records each representing an appointment. I have the name of the contactthe appointment is with, and the date. In another table I have a field that contains how many appointments each contact is supposed to have during the day. There are 12 entries for each contact, because some are expected to have different numbers during different months.
I am able to call up the data for the appropriate contactfor the appropriate month. It looks great in the graph when I count up the number of entries for Contact A and put next to it the expected number of entries from the related table.
The problem I'm running into now is that I need to add up all of the expected appointments between all of the entities. So:
::ContactName:: ::appointments:: ::expected::
Contact A 12 10
Contact B 33 34
Contact C 18 27
Getting the roll up for the actual appointments is easy, a simple COUNT summary field in a subsubsummary section. But what of the expected? Because ContactA had 12 appointments that means that there will be 12 records for them, so putting a summary field for the expected column is would return 120 for all Contact A's. Instead, given the dataset above, I need the calculation to return 71. Does this issue make sense? Any help would be greatly appreciated.
If I am following this correctly, you need to divide the amount of expected appointments between the entries of the group, then total the result. So something like:
Sum ( Entities::Expected ) / GetSummary ( sCount ; EntityID )
(this would be easier if we knew the names of your tables and fields).
P.S. The term "entity" has a specific meaning in the context of a relational database. Consider using another term (e.g. "contacts").
Added:
Using your example data, you should see the following results in the above calculation field:
in the 1st group of 12 records: 10 / 12 = .8333333333333333
in the 2nd group of 33 records: 34 / 33 = 1.0303030303030303
in the 3rd group of 18 records: 27 / 18 = 1.5
When you sum all this up (using a summary field defined as Total of this calculation field), you should get 71 (or a number very near 71, due to rounding errors).
Note: in the above calculation, sCount is a summary field defined in the Appointments table as Count of [ any field that cannot be empty ], and EntityID is the field by which your records are sorted and grouped (and it must be a local field).