SQL how to make a query to calculate percentage average of variables of survey in form - sql-server

I'm in a dying need for help. I'm absolutely no good in Access but I've taken a survey where I got 100 responses. I converted this from Excel to Acces.
Now, I've created a form where I've set checkboxes for each answers (see image 1)
So what I want to create is when I select some checkboxes of answers, and I'll click "Filteren" it shows next to the answers what the average percentage is of those answers that are checked.
Now, what I'm struggling with is the query, I have absolutely no clue how to start this.
I do have another table called "resultaten" (results) which would show the results of the checked answers, and I know I need to make a query from this table. (image 2)
So I want to create a query per answer that calculates the average but I have absolutely no clue where to start
Could someone please help me?

Related

DirectQuery with parameters PowerBI

I try to create report and have some table with some values my purpose is when clicking on some row of table it should drill through to other page with line chart, my question is I have column EventTime and when I click on some row it should drill through on line chart where as X axis will be time and that time should have range +-5 minutes of EventTime column how can I make this? Is this possible to create DirectQuery SQL statement with parameters and if possible how can I change this parameters depends on filtered row column EventTime or there are some other possibilites?
Kindly thanks for all answers!
For the moment I don't think they have exact solution for this, I also tried to do similar thing, Unfortunately couldn't found useful resource.
Try some custom visualizations, in import more visualizations, Obviously most of effective ones are paid versions, But you can do some stuff from free versions.

Pivot measure based on the pivot row label grouping

There is a table as shown in the pic
Is there a way to add a measure to the pivot created from the above data such that different error percentages can be used to different row label groups as shown in the pic?
If required I'm ready to do little bit of modification to the above source data, like adding some column or some calculation which should enable me to create such a measure but I'm really stuck here. Please help me out.
Update
Thanks to forums and members who constantly help people, I found out CONCATENATEX. So created three measures like below
Test_Group1=CONCATENATEX(GROUPBY(Range,Range[Group1]),LEFT(Range[Group1],1),"^")
Test_Group2=CONCATENATEX(GROUPBY(Range,Range[Group2]),LEFT(Range[Group2],1),"^")
Err=IF(SEARCH("^",[Test_Group2],1,0)=0,0.11,IF(SEARCH("^",[Test_Group1],1,0)=0,0.03,0.02))
Now Err is almost there but fails when single sub group items are there like in the pic. Tried to add dummy rows to the table by using UNION DAX function in the above measures but I'm missing something. Please help me out of this problem.
The answer is so simple. Please find the same in Power BI community forum.
Err = IF(isinscope(Range[Group2]),0.11,IF(isinscope(Range[Group1]),0.03,0.02))

Formatting Excel Table for Percent of total by specific column

I have a table in excel that I'm databasing information in. In this particular excel it is demographic data of students in a certain course across the state of Texas. You can see below that it is filtered by Ethnicity/Hispanic Latino.
Table Screenshot
It's clear to see that the percent row is utter-non sense. What I would really like this last column to do is tell me of what percent all those who took the survey are Hispanic. This becomes tricky because I would like to filter it for all of our "sub-data" as well. So whether I filter it for age, grade, most common language spoken, etc. I'd like to see the percent of that sub data there.
What do I need to do to accomplish this?
Thanks.
Use SUBTOTAL():
=[#Number]/SUBTOTAL(109,[Number])

Use a query to sort a report in MS Access

I am a beginner in MS Access and am currently stuck with a problem.
I have a database about movies and I'm currently creating a list of all the movies that I want to have sorted by popularity.
To determine the popularity of a movie I have a different table that has a history of what my customers have watched, every movie they have watched is a seperate entry in that table.
I have created a report that has 3 things, the title of the movie, the ID of the movie and a button to watch that movie. But I want to sort the report to show the movies with the most viewers first.
I have created this code in SQL Management Studio which works exactly like I want too:
SELECT [Film].[Titel], [Film].[Film_ID], COUNT([historie].[Film_ID]) as timesWatched
FROM [Film] INNER JOIN [historie] on [Film].[Film_ID] = [historie].[Film_ID]
GROUP BY [Film].[Titel], [Film].[Film_ID]
ORDER BY timesWatched DESC
I'm not that good with Access yet and have no idea how I can use this query to sort the report, I tried putting it in the row source (with everything on one line) in the report properties, which didn't work.
I hope someone has an idea on what to do, is it possible to use this query somewhere or should I use something else than a Report?
Thanks in advance for the answers!
If I'm not wrong..
First create the Query in ACCESS (Create tab -> query) There you will be able to create that query, save it, then go to your report and set its source to this query, the last step will be to set each textbox/label source to the query field, I mean if you have a textField in your report where you want to diplay "movieName", you must select data source from this text box and choose between all fields in your query (in this case, and following a good practice, let's say the field is called movieName too).

SQL - Compare 2 text fields

I’m using a software known as FME Desktop. In this software we can issue SQL commands through an item called a transformer. I’m using a transformer called a SQLExecutor that uses a very simple query to make a comparison. Below is an explanation of what I’m trying to do with this SQL Query and the fact that it does not work when trying to compare 2 text fields.
I believe my issue is a limitation of SQL when used in the SQLExecutor. Let's say I have a layer of data called TEST.LEASE and I want to compare it to a layer called EDIT.LEASE based on one unique ID field. Both of these layers are in the same database. We use SQL Server for our stored data. There is a TEXT field in both layers called GIS_ID. This is a unique ID field. So what happens is we get updates on our LEASE layer and they start off being loaded to TEST.LEASE. When we have done our QA/QC of the data and we are satisfied that they are ready to be uploaded to EDIT.LEASE we then run an FME job that serves as our promotion tool. What this promotion tool does is that it checks various fields in TEST.LEASE to make sure they qualify for being uploaded (this part works 100% without issue).
Right before they are promoted to EDIT.LEASE we need to know if this will be a completely new record, in which case we will do an INSERT with FME. If by chance the GIS_ID already exists then we need to do an UPDATE to those records. The tool we have works perfectly for determining if it is an INSERT or UPDATE, except for one seemingly small thing … IT ONLY WORKS IF THE TEXT FIELD CONTAINS A NUMBER THAT DOESN’T HAVE A LETTER IN IT.
FYI: Someone at our company decided to make the GIS_ID field a text field. In my opinion it should have been an integer field because comparisons would have been super easy. But I can't change that now, it has already been decided by people who make way more money than I do that it will be a text field.
As mentioned … The GIS_ID is a text field (in both layers and they are both the same size, there is no difference in the field in both layers). As you may know, SQL doesn't care if it is a TEXT field or an INTEGER field when all that is contained in that field is a number. It can still compare 202 to 202 to see if they are equal to each other. For my example let's say I have a record in both TEST.LEASE and EDIT.LEASE where both of their GIS_ID fields equal 09198760. When I run the query below it runs perfectly.
select OBJECTID
from TEST.LEASE_UPDATE_INSERT_WRITER
where GIS_ID = #Value(GIS_ID)
It runs perfectly, as I’ve mentioned, on the data if both GIS_ID text fields have only numbers in them. But if just one record contains an actual alpha, the SQL query will error out.
So if GIS_ID has 09198760a01 once the query reaches the “a” in GIS_ID a SQL error is returned. I’m not looking for a way for the job to continue and ignore those records, because I need ALL OF THE RECORDS to load. I need to know if anyone would know how to add to or rewrite the query above so that it loads both “number only text fields” and “numbers containing a letter fields.”
I hope that long explanation is clear. Please let me know if it isn’t. Thanks for any help you might be able to provide for me
Sincerely,
Tex
I am assuming that the #value is the function that is causing you problems. I briefly checked their docs. it looks like you need to encapsulate like so '#value(GIS)'
http://fmepedia.safe.com/articles/How_To/Executing-a-Stored-Procedure-on-Microsoft-SQL-Server-with-FME
Jeff is right and as a generic answer for regular sql users and even people using sql in their application code, if you are comparing text like the op mentioned, then you need to use single ' quotes '.
Where avalue = 'myvalue'
Otherwise sql server thinks it is an int, hence why it works when the value he's passing in is only numbers. It's not always easy to tell what the problem is when you're passing in parameters.
Where avalue = #myvalue
So you'll need to pay attention to that. Just wanted to mention this so maybe it helps someone else with a similar issue. I figured this out when we were getting errors from a field that had concatenated an id field i.e. it worked when the value = 2, but not 2,3 etc. Wrapping the parameter in single quotes easily fixed that as we were truly only concerned with value = '2' in our case.
Hope this makes sense.

Resources