Show difference in records - MS Access 2007 - ms-access

I have a subform with the following layout:
ID---Count---Difference---Weight---Difference
Populated with data looks like this:
ID---Count---Difference---Weight---Difference
1----5--------------------8.3----------------
2----9--------------------12.3---------------
3----16-------------------17.8---------------
How can I tell the difference between a record value and the one before it? Using the previous example, I'd like the Difference controls to look like so:
ID---Count---Difference---Weight---Difference
1----5-------0------------8.3------0---------
2----9-------4------------12.4-----4.1-------
7----16------7------------17.8-----5.4-------
As you can see, since record ID 1 is the first record, the difference is 0; however, ID 2 shows a Count Difference of 4 (9-5) and a Weight Difference of 4.1 (12.4 - 8.3); and ID 7
shows a Count Difference of 7 (16-9) and a Weight Difference of 5.4 (17.8 - 12.4).
Also note that the ID #'s do not necessarily increment one-by-one (there can be gaps).
How can I achieve the desired results? Expressions? VBA?
Any help with this is greatly appreciated!

Found my answer. Method 2 in this article described exactly what I need.

Related

How to get total from another tablix column? (SSRS)

Hello awesome people of stackoverflow!
I need help with a simple problem with my SSRS expression.
How could I do this in SSRS?
As you can on the 2nd table below in my excel screenshot.
for each row we divide -BC5...-BC10 to column/row BC4. To get the desired results for table 2 in excel column total 2018 into column/rows BC17 upto BC22.
I've tried referencing my textbox like this
ReportItems!TextBox1.Value / ReportItems!TextBox2.Value.
But got me the wrong values.
Can someone please help.
Thank you!
If those two tables are in the same table/tablix then it should work with the expression that you wrote (try to type it instead of copy paste sometimes that may work).
=(ReportItems!Textbox7.Value /ReportItems!Textbox1.Value) * 100
If they are not in the same Table/Tablix then you should write like the following:
=(Fields!ColumnName1.Value / Fields!ColumnName2.Value) * 100
Format your cells.
There is not enough info to give you an exact answer but you should be able to work it out.
The first thing you need to do is get the context of the aggregations you want to work with. So click on the cell containing the number you want to divide ([Sum(DiscountOERestated)] ). In the row and column groups panel near the bottom on the screen, look at the row group that is highlighted. For this example I'll assume the row group is called grpCategory.
Now we need to do the same for GrossCatalogRestated. However, GrossCatalogRestated in the top tablix does not appear to be an aggregate. I'll assume it should be the total GrossCatalogRestated for the dataset. For this exmaple, we'll say the dataset name is dsMyDataSet. If it's within a row group, just swap the dataset name out with the row group name that it sits in, just like we did for DiscountOERestated .
So you expression would look something like
=SUM(Fields!DiscountOERestated.Value, "grpCategory") / SUM(Fields!GrossCatalogRestated .Value, "myDataSetName")
This will give you a deicmal result, somehting like 0.025 . You then just need to set the format property to say, "p1", so it shows as 2.5%
If this does not work, edit your question to show the expressions in the cells you are working with along with the rowgroup and dataset names.

SSRS - Counting Correct Answers and Calculating Percentages via Comparison Fails

This is my first time using SSRS, so be gentle! I'm working on a report where I want to compare the number of correct answers to the number of all user answers for a group. The group repeats and looks set up okay, so that part isn't a worry. It's the calculation of a field that seems to be the worry.
Here's my dataset:
TopicID TopicName GroupScore TotalPossible QuestionID Question CorrectAnswer GroupAnswerScore UserAnswer
1 Test Topic 2 1 6 When did it start? 1917 1 1896
1 Test Topic 1 3053 Who was the 1200th governor? Olestra Chyppin 1 Brent Spoon
1 Test Topic 2 1 3053 Who was the 1200th governor? Olestra Chyppin 1 Olestra Chyppin
This query to calculate percentage based on correct answers compared to all answers does not work:
=IIF(Fields!UserAnswer.Value=Fields!CorrectAnswer.Value,1,0)/COUNT(Fields!UserAnswer.Value))
Likewise, this query to simply find the number of correct answers doesn't work:
=IIF(Fields!UserAnswer.Value=Fields!CorrectAnswer.Value,1,0)
Both return either zero (if I reverse the order on the percentage portion) or "infinity". I'd appreciate any help anyone can offer!
You need to get the aggregate of your data set. In this case you would use SUM. Your statement evaluates a single row and it is unclear which row. The statement to find the total number of correct answers would be
=SUM(IIF(Fields!UserAnswer.Value=Fields!CorrectAnswer.Value,1,0))
You may need to include a scope if you have groupings in your report. See the SSRS documentation here for more information.

Sorting/Ordering sequenced pairs of data in MySQL?

I am trying to determine if there's a way to sort rows of a MySQL table that consists of start/finish columns. (Could also be thought of as parent/child relations or other linked list arrangement)
Here's an example of how the data is currently stored:
id start finish
2 stepthree stepfour
6 stepfive stepsix
9 stepone steptwo
78 stepfour stepfive
121 steptwo stepthree
(The id numbers in this are not relevant, just using them to indicate additional columns of arbitrary data)
I want to sort/display these row in order, presuming I am always starting with "stepone", that traverses the start-> finish chain like, each "finish" being followed by the row with it as a "start".
desired output
9 stepone steptwo
121 steptwo stepthree
2 stepthree stepfour
78 stepfour stepfive
6 stepfive stepsix
There shouldn't be any branching/splits normally, just a sequential series of steps or states. I can't use simple alpha sorting (in my case the start and finish values are codes created by a customer), but can't figure out any other way to order these using SQL. I could programmatically do it using most languages, but stumped about doing it just with SQL.
Any clever ideas?
I would recommend having another table that has each step mapped to its precedence order.
Then you can write a query to sort each row in the order of precedence of the start step.

Computed Column Formula and how it can work base on condition

I have this challenge. I want to achieve a formula in a computed column. Currently my formula is: ((((([sponsorID]+' ')+substring(CONVERT([varchar],datepart(year,[DateCreated]),(0)),(3),(4)))+'-')+'0')+CONVERT([varchar],[ID],(0)))
Where: sponsorID, DateCreated, ID are columns in my table PatientInfo.
A sample of what the formular produce is PVT 11 10567
My ID column auto increment
Now The total no of record in my table called PatientInfo is getting to 500,000. and the formula i was given is [SPONSORCODE YEAR - 4 DIGIT]. It must not exceed 4 digit!
How do i achieve this formula in such a way that the id stops when a year ends and start afresh in a new year. i.e. patient folder no can be PVT 10 0128 ....... and PVT 11 0128. this is because in a year the total no of new patients will not exceed 4 digits. aside from the existing patients.
PLEASE Kindly assist. i hope i have provide a clear picture of my challenge. if there is a better way to achieve this, please assist.
awaiting your reply.
Would it work to use the last 4 digits of ID? For the ID part of the expression, you could use:
RIGHT('000' + CONVERT(varchar,[ID]),4)
Of course, you could get duplicates if you ever inserted more than 9999 rows in a particular year.
You can't using a computed column based on ID
You'd need a separate incrementing column per year and per sponsor that allows only 0000-9999. Then, use this in your computed column.
In the next version of SQL Server, you can use a sequence. Until then, you could use a sequence emulator: http://blogs.msdn.com/b/sqlcat/archive/2006/04/10/sql-server-sequence-number.aspx

grab mysql result based on field values

I am taking over designing a CMS from another programmer. As the site is filling up, we're finding loops in mysql queries causing long hangs. I have found a temp solution for this one, but am wondering if there is a quicker way of doing it?
take the table (tracks resources):
id resource click
1 res_1 192
2 res_2 12
3 res_3 300
what we need to get is a popularity of the resource - res_click/total_click
what he had was a while loop:
while ($item = mysql_fetch_array ($result)) $total_clicks = $total_clicks + $item[0];
As there could be 100 or more resources to a page, this was running for each resource, and it is causing major hangs.
My solution is to get a sum:
SELECT SUM(click) FROM uri
SELECT click FROM resource WHERE id=$x
then divide them both.
But this two calls are still running for around a 100 items per page. Is there a way I can have a field in mysql that is the result of a formula based on another another, like in excell? So I could add a field "percentage", tell mysql that it is the sum of click divided by the current click value, then every time click is updated the 'percentage' field is automatically updated?
any help would be appreciated,
cheers ;)
you can create a view on your table that present the sum you want