sum over date range in report (not query) - report

In Access 2010, I have a little form prior to a report which asks the user for a date range (e.g. 7.7.2015 - 9.9.2015). I pass this date range to the report as filter. The query contains the fields ActDate, Activity and Hours. I now want the report to look like:
Activities from <startDate> to <endDate>:
Activity Total Hours
Reading 5
Writing 8
Talking 3
What I'm getting is
Activities from <startDate> to <endDate>:
Activity Total Hours
Reading 2
Reading 3
Writing 1
Writing 3
Writing 4
Talking 1
Talking 2
The report should sum up equal activities over the selected date range and not display a separate line for each activity which just occured on a different date. Adding a group in the report for activities is no solution (it just adds extra blank lines).
I guess it's possible to build a custom query after the user dialog (in the query I could filter by date range and GROUP BY Activity), but it would be much simpler if the grouping could be done in the report without changing the query. Do I really have to change the query?

Related

Manipulating data from sqlite database

Am a beginner in android development and i am designing an android app which takes input of a date and stores it in sqlite database. Could you please explain how i can retrieve the date and use it to calculate other dates which i will display in another activity
Eg if input is 1/1/2019, i need to calculate events that occur after this date and display them in order of events and the date
Event 1 - 12/01/2019
Event 2 - 2/02/2019
Event 3 - 26/02/2019
Event 1 occurs after like 21 days, event 2 occurs after like 24 days
How should i perform this calculation and display them in another activity?
The link mentioned above is correct. To put it simply just use SQLite's date function - it can calculate dates quite easily:
SELECT date('2019-01-12', '+21 days');
gives you 2019-02-02.
Instead of the date value use a column name of your table if approbiate.
Take the calculated date for the second event and add 24 days and SQLite gives you the date for the third event.
SELECT date('2019-02-02', '+24 days');
2019-02-26
Hint: my answer only deals with the database side (cause that's what your question is tagged with). I have no idea about the Android programming.

How do I create a running count of outcomes sequentially by date and unique to a specific person/ID?

I have a list of unique customers who have made transactions over a year (Jan – Dec). They have bought products using 3 different methods (card, cash, check). My goal is to build a multi-classification model to predict the method pf payment.
To do this I am engineering some Recency and Frequency features into my training data, but am having trouble with the following frequency count because the only way I know how to do it is in Excel using the Countifs and SUMIFs functions, which are inhibitingly slow. If someone can help and/or suggest another solution, it would be very much appreciated:
So I have a data set with 3 columns (Customer ID, Purchase Date, and Payment Type) that is sorted by Purchase Date then Customer ID. How do I then get a prior frequency count of payment type by date that does not include the count of the current row transaction or any future transactions that are > the Purchase Date. So basically I want to do a running count of each payment option, based on a unique Customer ID, and a date range that is < purchase date of that training row. In my head I see it as “crawling” backwards through the transactions and counting. Simplified screenshot of data frame is below with the 3 prior count columns I am looking to generate programmatically.
Screenshot
This gives you the answer as a list of CustomerID, PurchaseDate, PaymentMethod and prior counts
SELECT CustomerID, PurchaseDate, PaymentMethod,
(
select count(CustomerID) from History T
where
T.CustomerID=History.CustomerID
and T.PaymentMethod=History.PaymentMethod
and T.PurchaseDate<History.PurchaseDate
)
AS PriorCount
FROM History;
You can save this query and use it as the source for a crosstab query to get the columnar format you want
Some notes:
I assumed "History" as the source table name - you can change the query above to use the correct source
To use this as a query, open a new query in design view. Close the window that asks what tables the query is to be built on. Open the SQL view of the query design - like design view, but it shows the SQL instead of the normal design interface. Copy the above into the SQL view.
You should now be able to switch to datasheet view and see the results
When the query is working to your satisfaction, save it with any appropriate name
Open a new query in design view
When you get the list of tables to include, switch to the list of queries and include the query you just saved
Change the query type to crosstab and update the query as needed to select rows, columns and values - look up "access crosstab queries" if you need more help.
Another tip to see what is happening here:
You can take the subquery - the parts inside the () above - and make
just that statement into it's own query, excluding the opening and closing (). Then you can look at it's design view to see what it does
Save it with an appropriate name and put it into the query above in place of the statement in () - then you can look at the design view.
Sometimes it's easier to visualize and learn from 2 queries strung together this way than to work with sub queries.

Google analytics syntax event label and or results don't match

I am new to querying GA with event label filters and am trying to work out my mistake with the following syntax. I have 3 different event label filters on 3 separate reports which are identical, except for the variation in this query:
Report filter 1: ga:eventLabel==Login - Create Account Step 2
Report filter 2: ga:eventLabel==Login - Create Account Step 2;ga:eventLabel!=Where to Buy Step 2 Submit Query
Report filter 3: ga:eventLabel==Login - Create Account Step 2;ga:eventLabel==Where to Buy Step 2 Submit Query
Now, I would expect that the count of sessions and users I get from report filter #1 would equal the sum of results from report filters #2 and #3. But actually, report filter #2: ga:eventLabel==Login - Create Account Step 2;ga:eventLabel!=Where to Buy Step 2 Submit Query returns counts of users and sessions orders of magnitude larger than the other 2 queries. (like 70K vs 120ish). Feels like there's a classic beginner conceptual error I'm making here, but I'm not sure how to google the the right question. Any ideas what I'm doing wrong?
Thanks for any help.
What you are trying to query with session/user metrics won't really work the reason being is that events are hits and so filtering that way filters on the hits. The way to get around that is to create segments of users that have triggered the events that you are interested in.
Now if you were to report on events/unique events using those filters based on the logic there I would expect #1 and #2 to return the same results and #3 to contain no values.

Visual FoxPro report total pages

I am able to get the total pages by doing steps as below:
REPORT FORM report NoConsole
lnMaxPages = _PAGENO
REPORT FORM report PREVIEW
but above only work if my report are all in the same group.
Let say I am printing 3 different reports (3 groups), and assuming each group have different pages. How do I display the correct lnMaxPages for each group?
Edit: I am using VFP 5 where there is no _pagetotal command.
You can write a UDF that stores the number of pages (use a variable in the report that only increments for each group) for example, the page number you are on when you are in group 1/2 or 3. Do some math and calculate the number of pages for each group. This will get you the variables when you run it noconsole. Display it on the report when you actually run it to the screen or printer.

Is this loop redundant?

The three tables of interest are:
Event, containing various details of, eg, the berlin marathon
Result, containing various fields including user's race time and a FK to an Event, and
Goal, with a FK to the Event the user would like to run, a field for the time they'd like to run it in, and eventually a FK to the Race at which the user achieved their goal.
Obviously, the Event of the Race where the user achieved their goal has to be the Event of the Goal. But not all Goal's have been achieved -- some may never be.
Is this bad design? Can anybody suggest a better way of modelling this problem? I'm using sqlite in a django project.
Your Event table is OK.
But your Goal Table design messed up the proposed event and the actual achieved event.
I think Result Table can be merged with Goal table into a new Result table.
Since one user may want to run multiple events. In your new Result table, it should be like:
UserID EventID TimeProposed ActualTimeUsed Achieved
1 1 1 hour 1.1 hour No
1 2 1.5 hour 1.2 hour Yes
So the loop you mentioned is removed since each row has only one event. (The UserID and EventID remains to be the FK to the other two tables.)
The Achived column can be updated using a query to decide ActualTimeUsed<=TimeProposed.

Resources