I want to store restaurant's monthly revenue (income and expenses), and later show it on a line graph for every year. I have come to this workaround I would store in year variable for example 2020-01-01 and then it should be adding values to all the following row for every month. Would it even work this way? Or should I use one date type and add months to it?
It can work, but it is not optimal.
For example if you want to see the yearly expenses you have to type every single month name into your query.
A more practical solution can be to use a single table with example columns like so:
date
is_expense (boolean)
amount (double)
restaurant_id
Where is_expense is boolean if the amount is income or expense.
You can aggregate from here everything: yearly / monthly expenses/incomes/profits etc.
You can use MySQL Functions like MONTH(date) that will give you specific month. For example if you want to aggregate all expenses for specific year & month you will do something similar to
SELECT SUM(amount) from Table WHERE is_expense=1 AND MONTH(date) = 1 AND YEAR(date) = 2020
I need to get the difference in hours and minutes of two times. For example 8:30AM and 2:14PM. I need to be able to subtract these to hours in Adobe Sign Formula expression. The supported function seem to support date based fields and not necessarily work right with only time. Here is the support page:
Add calculated fields to a form
I tried using datePart(part, date) and parsing first the hour and then the minutes. The problem is that this works if the value is a PM time (3:00PM) but if the value is an AM time (7:30AM) the function returns 0 instead of 7 (in the hours case)
datePart("h", "08:00:PM") = 8
datePart("h", "07:30:AM") = 0
I found out how to do this:
When creating the fields, make sure they are of type text and that the properties are as shown in the following image:
Notice the date format is a custom and with format h:nn tt, meaning that it only accepts values like 12:25 PM and 1:35 AM (no lower case am or pm). So suppose you have two fields like these: time_test1 and a time_test2, the third field instead will contain the number of hours will have this properties setup:
So, clicking on the F(x) in order to expand the formula expression, you need to put the following formula: dateDiff("h", [time_test2], [time_test1])
Also, click on Check syntax to make sure that it’s valid
Here is how it would look when I sign:
I hope this can be useful to others.
I'm very new to Google App Script so please bear with me. I'm trying to create custom functions in Google Sheets to monitor monthly and weekly sales and expenses. I can do it with built-in formulas, but it's too time-consuming to edit every cell every time. Here is what the Google Sheet looks like.
For monthly accounting, I use the formula below (here it's for "Sales"). I use the sum of multiple SUMIFS for the expenses since there are multiple criteria ("Supplies", "Staff", or "Operations").
=ARRAYFORMULA(SUMIFS('2019'!$F$2:$F,text('2019'!$A$2:$A,"MMM"),A3,'2019'!$E$2:$E,"Sales"))
For weekly accounting, I use another formula below. Here, I sum up all transactions (here "Sales") within a given range of dates (here Mar 31 2019 to Apr 6 2019). As in above, I use the same principle of summing up multiple SUMIFS functions for "Expenses".
Sales: =SUMIFS('2019'!$F$2:$F,'2019'!$A$2:$A,">="&date(2019,3,31),'2019'!$A$2:$A,"<="&date(2019,4,6),'2019'!$E$2:$E,"Sales")
Expenses: =SUMIFS('2019'!$F$2:$F,'2019'!$A$2:$A,">="&date(2019,3,31),'2019'!$A$2:$A,"<="&date(2019,4,6),'2019'!$E$2:$E,"Supplies")+SUMIFS('2019'!$F$2:$F,'2019'!$A$2:$A,">="&date(2019,3,31),'2019'!$A$2:$A,"<="&date(2019,4,6),'2019'!$E$2:$E,"Staff")+SUMIFS('2019'!$F$2:$F,'2019'!$A$2:$A,">="&date(2019,3,31),'2019'!$A$2:$A,"<="&date(2019,4,6),'2019'!$E$2:$E,"Operations")
How can I translate the formulas shown above into a custom function? I was trying to write something like this one:
I suggest a different strategy that avoids custom functions and allows you to use standard functions without complex parameters and, in the process, achieves a more logical layout of the data.
2019 Sheet: Category (Column E): make these a dropdown selection to avoid typos and other errors.
2019 Sheet: Column F - It's not clear whether sales should be normally negative (credit), or expenses should be normally positive (debit). Either way, the sum of this column will reconcile to something at some stage so the "sign" of transactions is important. It also means that formulas for Sales on the Summary Sheet should be prefixed with a negative (so that they appear as a positive number).
Summary Sheet-Monthly Sales - Prefix with a "minus" so that sales are shown as positive.
=-ARRAYFORMULA(SUMIFS('2019'!$F$2:$F,text('2019'!$A$2:$A,"MMM"),A3,'2019'!$E$2:$E,"Sales"))
**Summary Sheet: Monthly Expenses"" - Simplify the formula: just sum the values that are NOT "Sales"
=ARRAYFORMULA(SUMIFS('2019'!$F$2:$F,text('2019'!$A$2:$A,"MMM"),A3,'2019'!$E$2:$E,"<>Sales"))
Summary Sheet: Net - =B3-C3 (Sales minus Expenses)
Summary Sheet: Weekly reporting - It is always difficult to balance monthly results against weekly results. So much so, that many business adopt a quarterly cycle of 4/4/5 weeks to cater for the changes in the number of days per month. In any event, the formula that you are using is VERY complicated and prone to error through typos (if nothing else). I suggest:
create columns for the respective weekly "From"/"To" dates on the weekly report, and use date arithmetic to calculate the respective dates for each new week/month.
use Weekly Sales and Expenses formula that reference the "From/To" dates. This makes your formulas completely generic, enables you to copy formula with conventional "Copy/Paste" commands, and doesn't require detailed formula editing.
Consider whether you want the weekly results to align to the monthly results. If you do, then
fine-tune the month-end by adding or deleting days to the "To" date in week#4. The Week#1 "From" date for the following month will adjust automatically, as will the respective "From"/"To" dates for the other weeks in the following month(s). This will help eliminate unintentional errors such as including March 31 in both March week#4 and April week#1.
You might also add an extra three columns at the right to sum Total Sales, Total Expenses and Net profit for the four weeks. This figure will agree to the monthly result.
Formula simplification
By disclosing the From and To dates, you can use those dates in your SumIFS formula.
For example, March Week#1:
Sales: =-SUMIFS('2019'!$F$2:$F,'2019'!$A$2:$A,">="&G3,'2019'!$A$2:$A,"<="&H3,'2019'!$E$2:$E,"Sales")
Expenses: =SUMIFS('2019'!$F$2:$F,'2019'!$A$2:$A,">="&G3,'2019'!$A$2:$A,"<="&H3,'2019'!$E$2:$E,"<>Sales")
Monthly Results
Sales: =-ARRAYFORMULA(SUMIFS('2019'!$F$2:$F,text('2019'!$A$2:$A,"MMM"),A3,'2019'!$E$2:$E,"Sales"))
Expenses: =ARRAYFORMULA(SUMIFS('2019'!$F$2:$F,text('2019'!$A$2:$A,"MMM"),A3,'2019'!$E$2:$E,"<>Sales"))
Net: =B3-C3
Weekly results - extract
Week#1 Results
Sales: =-SUMIFS('2019'!$F$2:$F,'2019'!$A$2:$A,">="&F3,'2019'!$A$2:$A,"<="&G3,'2019'!$E$2:$E,"Sales")
Expenses: =SUMIFS('2019'!$F$2:$F,'2019'!$A$2:$A,">="&F3,'2019'!$A$2:$A,"<="&G3,'2019'!$E$2:$E,"<>Sales")
Net: =H3-I3
Week#2Results
Sales: =-SUMIFS('2019'!$F$2:$F,'2019'!$A$2:$A,">="&K3,'2019'!$A$2:$A,"<="&L3,'2019'!$E$2:$E,"Sales")
Expenses: =SUMIFS('2019'!$F$2:$F,'2019'!$A$2:$A,">="&K3,'2019'!$A$2:$A,"<="&L3,'2019'!$E$2:$E,"<>Sales")
Net: =M3-N3
Date Arithmetic
March Week#1 From: Mar 1 2019 (the only date that is entered manually)
March Week#1 To: =F3+6
March Week#2 From: =G3+1
March Week#2 To: =K3+6
March Week#4 To: =U3+6+3
April Week#1 From: =V3+1
I'm trying to organize a query which should print a count of items ordered by a time unit such as a hour, a day etc.
My limitation is that I'm using LovefieldDB javascript library and complex queries are limited.
I have a table of Units where the main field is the date of creation like this:
2017/11/29 08:17
2017/11/29 08:47
2017/11/29 09:25
2017/11/29 11:39
The result I expect is to count per hour the number of items:
08:00 (2)
09:00 (1)
11:00 (1)
What I want to avoid is to select all rows and process them in a loop because this software is going to have thousands of rows and I'll have to create similar queries for day, month and also year.
A possible solution I thought is to add 4 more datetime fields where I would save created_hour, created_day, created_month, created_year so I can order them easly.
Do you have some tips?
This is what I mean. You can format the time to be in hours and group by the formatted time.
SELECT DATE_FORMAT(datecolumn, '%H:00'), COUNT(*)
FROM SOURCETABLE
GROUP BY DATE_FORMAT(datecolumn, '%H:00')
Math isn't really my thing, but what I'm trying to figure out is how to predict/estimate the next number from a dataset.
Let's say I have an array:
var values = new Array(1,4,3,5,6,10,4,15);
Does anyone know a formula in javascript that could guess the next number after 15 based off the previous values in the array.
Basically I have an array of total numbers from daily sales, each item in the array is the total for a single day. So I'd like something that could guess what tomorrow's sale might be.
Based on the data you're providing, it seems you can only predict what tomorrow's sale might be by taking the average of your dataset.
If you had additional data, say, day of the week, you could take the average of all sales on Tuesdays, and then make a prediction based off of that average.
Have a look at the various moving average methods - you can choose whichever suits your application best.