Is there a formula for upcoming date using formula in Google sheet based on condition? - date

I have a google sheet where I need to get the next upcoming date based on the start date set in column A
Any pointers are greatly appreciated? I am unable exhibit the efforts as I am completely new to this sort of recurrence using Google sheets
https://docs.google.com/spreadsheets/d/1g_UNg4MjDy3gFufpjZtMRkbBz80K3scQdZOaiAnZi7I/edit#gid=0

This behavior (the next date from today including today) could be implemented manually by this formula:
={
"Next date from today";
ARRAYFORMULA(
IFS(
A2:A >= TODAY(),
A2:A,
B2:B = "Daily",
TODAY() + MOD(TODAY() - A2:A, C2:C),
B2:B = "Weekly",
TODAY() + MOD(TODAY() - A2:A, 7 * C2:C),
B2:B = "Monthly",
EDATE(A2:A, ROUNDUP((12 * (YEAR(TODAY()) - YEAR(A2:A)) + (MONTH(TODAY()) - MONTH(A2:A)) - IF(DAY(TODAY()) < DAY(A2:A), 1, 0)) / C2:C, 0) * C2:C),
True,
""
)
)
}
For additional options (like "every 2nd monday of the month" and others) additional options should be implemented in that IFS part.
If you are interested in a trivial case where the next date from the start date (column F:F on the screenshot) is needed, then the formula would be much simpler:
={
"Next date";
ARRAYFORMULA(
IFS(
B2:B = "Daily",
A2:A + C2:C,
B2:B = "Weekly",
A2:A + 7 * C2:C,
B2:B = "Monthly",
EDATE(A2:A, C2:C),
True,
""
)
)
}
Again, for additional options you'll need to add corresponding part to the IFS.

You could use IFS to check Frequency, and:
If Daily, add Count value to start date.
If Weekly, add Count value multiplied by 7.
If Monthly, since not all months have the same duration, retrieve the YEAR, MONTH and DAY indexes, add Count to the MONTH index, and set a new DATE, EDIT: or as suggested by kishkin, use EDATE.
It could be something like this:
=ARRAYFORMULA(IFNA(IFS(
B2:B = "Daily", A2:A + C2:C,
B2:B = "Weekly", A2:A + 7 * C2:C,
B2:B = "Monthly", EDATE(A2:A,C2:C)
)))

Related

Rewrite dynamic T-SQL date variables in DAX

We're currently rebuilding basic emailed reports built using T-SQL to be paginated reports published on Power BI.
We're muddling through by creating the tables we need with the appropriate filters in Power BI Desktop to reconcile the numbers, then taking the DAX code from them using the Performance Analyser.
The one I'm working at the minute has a simple bit of SQL code to get data for a previous calendar month. I have no idea how or if it's possible for this to exist in DAX?
-- Validation to get previous month
IF (MONTH(GETDATE()) - 1) > 0
SET #MONTH = MONTH(GETDATE()) - 1
ELSE
SET #MONTH = '12'
-- Validation to get year of previous month
IF (#MONTH < 12)
SET #YEAR = YEAR(GETDATE())
ELSE
SET #YEAR = YEAR(GETDATE()) - 1
-- Set start date and finish date for extract
SET #PERIOD = #YEAR + RIGHT('00' + #MONTH, 2)
It needs to become a hidden SSRS parameter or just inline code to be used with this DAX variable:
VAR __DS0FilterTable =
TREATAS({"202212"}, 'Org View_VaultexCalendar'[Calendar Month No])
So the "202212" would become #period or the equivalent if doable without a parameter.
SSRS Parameter:
=IIF(
Month(Today()) > 1,
Year(Today()) & RIGHT("00" & Month(Today()) - 1, 2),
Year(Today())-1 & "12"
)
DAX expression:
IF (
MONTH ( TODAY () ) > 1,
YEAR ( TODAY () ) & FORMAT ( MONTH ( TODAY () ) - 1, "00" ),
YEAR ( TODAY () ) - 1 & "12"
)
In both cases we look at today's month and check if it's after January. If it is, take the current year and concatenate it with the current month less one and padded with a leading zero when needed. In the other case we know that the month is January so take the current year less one and concatenate it with "12"

How to merge individual date fields like order day, order month and order year to create a order date?

Ex. Order Day "1"
Order Month "Jan"
Order Year "2020"
Required Date: 1 JAN 2020
If each of these are separate fields, I would build a text version of the date and wrap it in the DATE() function, but there are probably a dozen ways to do it differently.
DATE( [OrderYear] + "-" + [OrderMonth] + "-" + [OrderDay] )
Let's assume your data is
Step-1: Convert all three fields to string type, if not so.
Step-2: create a calculated field say order date full with the following calculation
DATE(DATEPARSE("dd:MMM:yyyy", [order date] + ':' + [order month] + ':' + [order year]))
get results like this

How to check whether day satisfies the recurrence condition using google sheet formula

I have a Google sheet where it has startdate, frequency, count. I need to check whether the todays date is satisfying the recurrence and display TRUE if today() is satisfied and false if not satisfied.
This will help me determine each time, the sheet is opened I can find out from TODAY() date is satisifed or not?
https://docs.google.com/spreadsheets/d/142od5eUib5nHmdi4mnENuPbh-Yn485NzUSt90p84QE0/edit?usp=sharing
Like #Scott Craner said, just compare the result of the formula from the previous question with TODAY():
={
"Today is the day?";
ARRAYFORMULA(
IF(
A2:A = "",
,
IFS(
A2:A >= TODAY(),
A2:A,
B2:B = "Daily",
TODAY() + MOD(TODAY() - A2:A, C2:C),
B2:B = "Weekly",
TODAY() + MOD(TODAY() - A2:A, 7 * C2:C),
B2:B = "Monthly",
EDATE(A2:A, ROUNDUP((12 * (YEAR(TODAY()) - YEAR(A2:A)) + (MONTH(TODAY()) - MONTH(A2:A)) - IF(DAY(TODAY()) < DAY(A2:A), 1, 0)) / C2:C, 0) * C2:C),
True,
""
) = TODAY()
)
)
}

Daily interest calculator that's supposed to credit monthly given various user inputs

I'm new to programming and have been working on something to learn Python for the last few days. I'm trying to create a program that calculates daily interest and credits interest monthly given user generated inputs.
The good: The program can add deposits to the initial balance every 14 days as I wanted. The program is able to determine whether an input is a leap year or not. The program is able to determine the daily interest.
The bad: I haven't been able to figure out how to get the program to sum the calculated daily interests for a given month then add it to the beginning balance of the next month.
import datetime
from datetime import date
from datetime import timedelta
import calendar
from decimal import Decimal
def gupta():
print("Enter a start date in YYYY-MM-DD format")
date_entry = input() #records account's start date as string
year, month, day = map(int, date_entry.split('-')) #splits contents of date_entry string variable into separate integers thus rendering date1 variable actionable by datetime.date
date1 = datetime.date(year, month, day) #records account's start date as datetime.date (module?)
print("Enter an end date in YYYY-MM-DD format")
date_entry = input() #records account's end date as string
year, month, day = map(int, date_entry.split('-')) #splits contents of date_entry string variable into separate integers thus rendering date1 variable actionable by datetime.date
date2 = datetime.date(year, month, day) #records account's end date as datetime.date (module?)
print("The starting date is " + str(date1) + " and the ending date is " + str(date2))
print("Enter your initial balance")
initial_balance = Decimal(input()) #requests initial balance (assumes this is amount to be deposited every 14 days)
print("Enter your interest rate (as a decimal)")
interest_rate = Decimal(input()) #records interest rate as a decimal
date1 = date1.toordinal() #changes date1 to ordinal
date2 = date2.toordinal() #changes date2 to ordinal
list_interest = []
for current_date in range(date1, date2 + 1): #cycles through date1 and date2 using a step/iteration of 1
date_spread = current_date - date1
new = current_date + 1
print(date.fromordinal(current_date).strftime('%Y-%m-%d'))
print(list_interest)
if date_spread != 14: #checks to see whether additional deposit is going to be made
current_date = date.fromordinal(current_date)
new = date.fromordinal(new)
current_date_y = str(current_date.strftime("%Y"))
new_m = str(new.strftime("%m"))
current_date_m = str(current_date.strftime("%m"))
current_balance = initial_balance + 0
print(current_balance)
if calendar.isleap(int(current_date_y)):
daily_interest = round(current_balance * (interest_rate / 366), 2)
print(daily_interest)
if current_date_m == new_m:
list_interest.append(daily_interest)
print(list_interest)
else:
daily_interest = round(current_balance * (interest_rate / 365), 2)
print(daily_interest)
if current_date_m == new_m:
list_interest.append(daily_interest)
print(list_interest)
current_date = date.toordinal(current_date)
elif date_spread == 14: #checks to see whether additional deposit is going to be made
current_date = date.fromordinal(current_date)
new = date.fromordinal(new)
current_date_y = str(current_date.strftime("%Y"))
new_m = str(new.strftime("%m"))
current_date_m = str(current_date.strftime("%m"))
current_balance = initial_balance + 150
initial_balance = current_balance
print(current_balance)
if calendar.isleap(int(current_date_y)):
daily_interest = round(current_balance * (interest_rate / 366), 2)
print(daily_interest)
if current_date_m == new_m:
list_interest.append(daily_interest)
print(list_interest)
else:
daily_interest = round(current_balance * (interest_rate / 365), 2)
print(daily_interest)
if current_date_m == new_m:
list_interest.append(daily_interest)
print(list_interest)
current_date = date.toordinal(current_date)
new = date.toordinal(new)
date1 = current_date
list_interest = []
#print(current_balance)

Using expression in pick function

I have tried Num((today()-I_TRAN_DATE)/90 + 1,0) individually and it will return integer, but it seems not working when I try to combined it with pick function. I know it's not finished but should at least return result for 1-3
pick(
Num((today()-I_TRAN_DATE)/90 + 1,0)
,'less than 3 months'
,'3-6 months'
,'6-12 months'
,'greater than 1 year'
)
This looks like an issue with passing the number from the expression to the pick function. When using the num function, this does not change the underlying value - including a few more brackets and a round function resolves the issue as per the below script which generates a list of dates and then applies the pick function at the end.
Let varMinDate = Num(31350); //30/10/1985
Let varMaxDate = Num(42400); //31/01/2016
TempCalendar:
LOAD
$(varMinDate) + Iterno()-1 As Num,
Date($(varMinDate) + IterNo() - 1) as TempDate
AutoGenerate 1 While $(varMinDate) + IterNo() -1 <= $(varMaxDate);
TestCalendar:
Load
TempDate AS I_TRAN_DATE,
week(TempDate) As Week,
Year(TempDate) As Year,
Month(TempDate) As PeriodMonth,
Day(TempDate) As Day,
if(Year2Date(TempDate),1,0) as CurYTDFlag,
if(Year2Date(TempDate,-1),1,0) as LastYTDFlag,
inyear(TempDate, Monthstart($(varMaxDate)),-1) as RC12,
date(monthstart(TempDate), 'MMM-YYYY') as MonthYear,
Week(weekstart(TempDate)) & '-' & WeekYear(TempDate) as WeekYear,
WeekDay(TempDate) as WeekDay,
if(TempDate>=MonthStart(AddMonths(Today(),-12)) and(TempDate<=MonthStart(Today())),1,0) as Rolling12Month
,'Q' & Ceil (Month(TempDate)/3) as Quarter
,Year(TempDate)&'-Q' & Ceil (Month(TempDate)/3) as YearQuarter
,if(Year(TempDate)=(Year(Today())-1),1,0) as LastYear
, if(MonthStart(TempDate)=MonthStart(Today()),null(),'Exclude Current Period') As ExcludeCurrentPeriod
Resident TempCalendar
Order By TempDate ASC;
Drop Table TempCalendar;
Let varMinDate = null();
Let varMaxDate = null();
PeriodTable:
Load
Pick(round((num((((today()-I_TRAN_DATE)/90) + 1),0)),1)
,'less than 3 months'
,'3-6 months'
,'6-12 months'
,'greater than 1 year') as Period
,I_TRAN_DATE
Resident TestCalendar;