Showing a calculation of % of Referrals from from MD's in access - ms-access

I have a table that is based on data entered into a form for new patients to our clinic. One of the parts of the form is a check box that shows if a patient will need one or multiple disciples (Speech, Physcial, Occupational, Feeding Therapies) to our staff and is stored in the tables as 0 and -1.
I would like a simple way to show how many we have for each discipline unsing a subform or query that I can then refrence and then calculate it as a %
Example:
ST: 550 55%
OT: 200 20%
PT: 100 10%
FT 150 15%
Total: 1000
We just recently switched from a Google Sheet for all this data to Access. I was able to do a very very easy and simple PivotTable with Sheets, but the pivot tables in Access make me want to throw things.

Welcome to MS Access. you can achieve this by using count function:
SELECT Count([Speech])*100/Count([patient_id]) AS TotalSpeech,
Count([Physical])*100/Count([patient_id]) AS TotalPhysical,
Count([Occupational])*100/Count([patient_id]) AS TotalOccupational,
Count([Feeding ])*100/Count([patient_id]) AS TotalFeeding
FROM tbl_patient;
of course you need to change the column names as per your table. the calculation is count(therapyType) * 100 divide by total patient = % of TherapyType used by patients.

Related

Power BI topn function: Problem with topn function returning more than n rows due to duplicates

This is the current data table that I have, which is called 'Potential High Usage'
CLICK TO SEE DATA TABLE
I tried to use the TOPN function to create a table of the top 10 'User ID' based on the 'Number of clicks'. This is how I tried to do it:
High Usage IDs = topn(10,'Potential High Usage',[Number of clicks])
The problem is that it returns 11 rows instead of 10. I am thinking that its because I have many duplicates for the least number of clicks that will still be considered as top 10 (Number of clicks = 2). I was wondering if there is a way to return ONLY 10 rows?
Yes. TOPN will return more than N rows when there are ties at Nth row.
See the Microsoft TOPN dax function documentation.
First add index column using power query.
Then use following DAX to return top 10 rows.

referring to sum of elements in column with Microsoft Access 2010

My employee's IT department refuses to install R for me (claiming the open source version is a security risk) and I tried to create reports with Microsoft Access 2010.
I got stuck trying to create a query on a simple table of hospital wards (for the purpose of keeping track of a data collection exercise):
I did not manage to allocate each ward a sample size that would be proportional to its bed capacity (third column above) as I was not able to refer to the sum of the elements in the "bedCapacity" column. With Excel, I would try something like this:
Cell D2 in Excel contains =INT(C2/SUM(C$2:C$6)*50)+1 and cells D3 to D6 according formulae.
Is there any way I can refer to the sum in the bedCapacity column in Access 2010? I tried creating a separate query that would sum up the the 'bedCapacity` column, however could not figure out how to refer to the value in that query.
I'm trying to use Access 2010 so I can create standardised reports for the data collectors on their progress (which is not easily possible with Excel 2010, as it requires too much manual manipulation - I tried pivot tables etc.).
Would be grateful for any insights.
Create and save this query to give you the total bed capacity from all wards.
SELECT Sum(bedCapacity) AS TotalBeds
FROM YourTable;
Replace YourTable with the name of your table, of course. For the rest of this answer, I will pretend you saved that query with the name qryGrandTotalBedCapacity.
Then you can use that query in another where you cross join it with your table. The cross join gives you a result set which pairs each row of one data source with every row of the other data source.
However, since qryGrandTotalBedCapacity returns only a single row, this amounts to just making the TotalBeds value available for every row of YourTable. And, from that starting point, it is easy to translate your Excel formula to the Access SQL equivalent.
SELECT
y.ID,
y.ward,
y.bedCapacity,
(INT((y.bedCapacity/q.TotalBeds) * 50) + 1) AS sampleSize
FROM YourTable AS y, qryGrandTotalBedCapacity AS q;
My RoundSum function will do that:
Public Sub ListSampleSizes(ByVal BedCapacity As Variant, ByVal SampleSum As Long)
Dim SampleSizes As Variant
Dim Item As Long
SampleSizes = RoundSum(BedCapacity, SampleSum)
For Item = LBound(SampleSizes) To UBound(SampleSizes)
Debug.Print Item + 1, BedCapacity(Item), SampleSizes(Item)
Next
End Sub
Result:
1 22 12
2 18 10
3 20 11
4 16 9
5 19 11
Too much code to post here, but full code is for download at GitHub: VBA.Round

Access Dynamic entry form

First off my Access skills are sub-par, but I'm fairly certain that it is the direction I need to go for my project so I'm hoping I can get some feedback to direct my research. I am however well versed at Excel, VBA and Matlab so I'm not completely incapable, I hope.
I need to assemble a system to track emissions (chemicals) from a variety of sources (units). Each unit has its own set of possible emissions and they need to be tracked daily (but also have the capability to be entered for multiple days at the same time).
What I would ideally like to have is an entry form that initially has 2 dropdown boxes, one to select the month/year and the other to select the unit.
Once selected I would like to auto populate a table that has the entire months dates in column 1, and then all of the possible emissions for that unit in the next 2:N columns. Then I would like to query the existing database to populate any data that has already been entered for the date/unit combination.
At this point need to let the users input new data, either for just one day or for numerous days. Then save it to the database.
I have approximately 70 possible emissions and approximately 40 units. I will need to be able to add new units and specify their chemicals as well as add new chemicals to existing units as their duties change. I would also like the ability for multiple users to be entering data simultaneously, which I believe is a hallmark of Access and may not be something I have to "turn on".
I hope that there is a way that Access can help me do this and not necessitate using Excel (which is very clunky in this case).
Thanks in advance,
Ben
The format for the data can simply be:
Date Unit Chemical1 Chemical2 Chemical3
1/1/16 UnitA 0 0.1 0
1/1/16 UnitB 0 0.3 0.2
1/1/16 UnitC 0.2 0 0.5
I'll need to do more analysis of the data, but given it as shown would be more than sufficient for the remainder of the work.
For the data entry from I would like to have two drop down boxes: (1) Month/Year and (2) Unit Name. And then the form that the users would fill in would list each day of the month in the left-most column and then give all of the chems that unit could emit in the following columns.
So if:
Unit1 was able to emit ChemA and ChemC
Unit2 was able to emit ChemB
Unit3 was able to emit ChemA, ChemB, and ChemC
So the entry form for Jan-2016 for Unit1 would give them the following assuming today is the 3rd and they have entered data for the 1 and 2.
(1)Jan-2016 (2)UnitA
Date ChemA ChemC
1/1 0.1 0.2
1/2 0.2 0.1
1/3
Then selecting unit 2 would change the available columns and again show the last 2 days entries and allow for the entry of today
(1)Jan-2016 (2)Unit2
Date ChemB
1/1 0.1
1/2 0.2
1/3
Finally Unit3 has all 3 chemicals available and would show the previous data and the blank entries.
(1)Jan-2016 (2)UnitB
Date ChemA ChemB ChemC
1/1 0.1 0.1 0.1
1/2 0.2 0.2 0.2
1/3
I don't mind (and would prefer) that all of the dates for a month were populated and not just the next date. So that January would have 31 rows, Feb would have 29 (this year), etc, etc.
01-21-2016
Wayne, my current tables are:
UnitList
ID UnitName UnitOwner UnitLocation UnitDesc AllowedChems
The last column AllowedChems, is a multiple selection that is linked to the table ChemicalList which looks like:
ID ChemicalName MassUnit Type
Where all of the entries from ChemicalName are possible selection in the AllowedChems field of UnitList
Then I have a table called Tracking with the columns:
ID EDate UName Vent ThOx
At the end of this list I would like to have a column for each of the chemicals listed in ChemicalList, that way the users can input a number for the mass of that chemical they are emitting and it will be transferred to the correct column. But I'm as yet unable to determine if I'm able to build columns by linking them to the contents of another table. Perhaps there is another way around this?
For example if my chemicals are listed in the ChemicalList table as:
ID ChemName
1 ChemA
2 ChemB
3 ChemC
Then I want the Tracking table to look like:
ID EDate UName Vent ThOx ChemA ChemB ChemC
And grow each time a new chemical is added.

Using running totals in MS access report cumulatively

I am developing a db (MS access 2010) to support a school with a well-defined model for tuition quotation. The list of products is assembled for each quote, then various discounts are applied. The discounts may be a percentage or an absolute dollar amount. So far, so easy. The problem is that their business logic requires:
No limit on number of discounts.
Specific discounts to be applied in a defined sequence (implemented in my case with a "discount ordinal" column, values 1 (first applied) to 100 (last applied).
Each sequential application of a discount is to the running total of the quote. Eg: Total products $1000. Discount: 50%. Value: $500. Subtotal $500.
Subtotal: $500. Discount: $25. Value: $25. Subtotal: $475.
Subtotal: $475. Discount: $10%. Value: $47.50. Subtotal: $427.50.
This appears to be a variation of the "get the value of the field in the previous row" problem, but with the added twist that the "value of the field" is actually a cumulative calculation. It has the flavor of recursion: while discounts remain, subtotal(previous subtotal).
I have no clear idea how to implement this in a report, because the calculation as noted above is self-referential. I'm not looking for code here, just guidance on the general approach to the problem (ie, some kind of global variable, using VBA - in which case, I'm not sure what the "glue" between the query in VBA and the report would be - or some trick with a calculated field although I've spent a lot of time trying to figure one out). Any thoughts?
In that kind of situations, I always create a new table, that will get filled up when the report opens, and base the report in that table, not the original one. That way I can do all the calculations I need, even making several passes. The report then is simply a "dump" of the table. Complex totals can be additional columns, that will be shown only in the totals section.
You could have table for purchase history using an integer to link each purchase since an autonumber by itself will not link each discount stage.
So in excel I would use something like this:
v = Starting Value
i = 1
Do Until i = Last Discount
d = ws.Cells(i, 9).Value
v = v * (1 - d)
ws.Range("B2").Value = v
i = i + 1
Loop
At each stage you could write to the table (using docmd.runsql) the discount applied (d) and the value (v) but it could be quite slow. You could then order the table by purchase identifier then descending by value since sequential discounts will inherently order correctly.

Reporting services: Total and percentages for each row

I want a result to look like this (converting from a solution in Excel to reporting services):
Campaigns Success Not Success Total Success % Not sucess %
Campaign 1 1 4 5 20% 80%
Campaign 2 4 4 8 50% 50%
How do I accomplish this task? I can add the Total column, without any problems - but I don't know how to add the Success % and Not success % columns.
I think to add new columns you just need to right click and add a new column?
For the "=Details" field of the Success % column, right click and select "expression" to get to the expression editor. Then enter the following expression
=(Fields!Success.Value/Fields!Total.Value) * 100
For the Not success column do similar except your expression would be
=(Fields!NotSuccess.Value/Fields!Total.Value) * 100
(obviously the names of the actual database fields may be different in your situation)
To add to Calanus's answer, you can format the cell to show a percent via its Right-Click Properties or by using the FORMAT function.
=FORMAT((Fields!Success.Value/Fields!Total.Value), "P")
=FORMAT((Fields!NotSuccess.Value/Fields!Total.Vlaue), "P")
If you are using a matrix then you can use the group to divide by either column or row, i.e.,
=round((Fields!count.Value/sum(Fields!count.Value,"matrix1_RowGroup1") * 100,2) & " %"
the field count would be the total of any given category
Example of record set
CAMPAIGN COUNT TYPE
Campaing1 1 Success
Campaing1 4 Not Success
Campaing2 4 Success
Campaing2 4 Not Success