Finding a max value restricted by Date - date

First of all thank you for the treasure of information! I have found many answers so far but I have run into an issue I cannot solve.
I run a database with vehicles involved and beginning mileage is something I would like to automate. I have tabs all keeping a tally of beginning and ending mileage based on a query of the main index of all trips. I have been using a vlookup function but I have found that it is quite fragile (amongst other calculations) and I have been converting them over to script in the hopes that it remains more robust (ie accidentally typing in a calculated field....which wipes thousands of trips in a single stroke. Since they are Vlookup currently I have to go back and systematically restore the correct calculation (takes a couple of hours to do).
My first attempt is here:
1: On the main page I would utilize vlookup which I restricted with a status:
=arrayformula(if(M2:M="Ready",vlookup(J2:J2287,'Vehicle Lifecycle'!$A$2:$L$30,7,false),O2:O2287))
2: On the Vehicle Lifecycle page I utilized a max formula which looks up the max mileage constantly for maintenance costs per mile:
=max('C-2'!$F$2:$F)
I would like to script a restriction with a date (meaning it doesn't look up a max after the date of the trip).
Or, if it might be more direct, find a way to lookup the last previous trip with the vehicle and pull the ending mileage.
Currently I have this as a script but I am just getting started with scripting so forgive my ignorance. I am a quick study however and so far I am doing well...ish
function myfunction()
{
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lr = ss.getLastRow();
ss.getRange("O2").setFormula("=iferror(max(indirect(\"'\"&J2&\"'!$F$2:$F\")),\"\")");
var filldownrange = ss.getRange(2,15, lr-1);
ss.getRange("O2").copyTo(filldownrange)
}
This is perfect for pulling the max value from the appropriate tab so I'm close. Can anyone help me get the cigar?

I got it!!! I started working with a formula and I bumped into a problem when I looked for just the date on vlookup. The solution was subtracting 1 from the date and looking for that.
function onVehicleSelection()
{
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lr = ss.getLastRow();
ss.getRange("O2").setFormula("=iferror(vlookup(to_date(minus(C2,1)),indirect(\"'\"&J2&\"'!$B$2:G\"),5,true),\"\")")
var filldownrange = ss.getRange(2,15, lr-1);
ss.getRange("O2").copyTo(filldownrange)
}
However if someone has a more elegant solution I would be interested to hear it. I could definitely use some pointers on triggers as I will be working on those after I figure out how to do about 8 more calculations in script. So far I have been lucky enough to have functions that translate nicely.

Related

Anylogic: Time depending stock in-flow with table functions

I would like to simulate a stock (array with six different dimensions) and its changes over the years in Anylogic. The initial values of the stock are given as well as the changes over the years (Excel table format). I think the values of the stock changes can't be describes by a constant mathematical function. So, they need to be implemented in the model as a table.
My approach was to create the stock and also the in-flow as an array with the six dimensions. I entered the initial values in the stock (inital values of stock). After that, I created six table functions with the number of the year as the argument and the change value of the stock in this year in the value column (example of a table funcion). To get the particular in-flow for the current simulation year, I entered the table function in the in-flow and set a variable as an argument (inflow of the stock). For the variable I entered a function, which I found on the Anylogic help website. It is the following: int getYear(Date date) (current year variable).
So as my understanding is right, this variable should give out the current year of the simulation as an integer. Using this value as a argument for the table function, I was thinking the model should work, but it seams that there is a problem the variable for the current year. I hope this was understandable. If not, please don't hesitate to ask.
Do you have any idea what could be the mistake or what I can do better to create a working model?
Thank you very much for your help.
Have a nice day and stay save
David
I've been looking for an answer to the same situation as yours, but wasn't able to find the clear guide for it.
In my case, I added an 'event' variable from the agent-based simulation palette with Trigger type == 'Timeout', Mode == 'Cyclic', and both First occurrence and recurrence time as 1 (in 'years' in your case).
Then, try to set actions for the event variable as what you intended:
Veraenderung_Lkw_Flotte [Nicht_Autom] = Veraenderung Nicht Autom pro Jahr(time());
Veraenderung_Lkw_Flotte [AF_Stufe_1] = Veraenderung Stufe 1 pro Jahr(time());
Veraenderung_Lkw_Flotte [AF_Stufe_2] = Veraenderung Stufe 2 pro Jahr(time());
Here, the time() returns the current model time. You may need to use different specification depending on your time specification.
Hope you find it helpful.

MS Access use DATE() in a calculated field

I am using Microsoft Access 2016. I am trying to find out how many years exist from the current year until a future year. I have a column that is end_date. I am trying to create a calculated field that is essentially YEAR(end_date) - YEAR(current_year). I tried to use YEAR(DATE()) but DATE() is not allowed to be used in a calculated field apparently.
Is there no way to do a calculation like this?
Nope. Calculated fields are cached and static, so are NEVER allowed to contain ANY information that will change over time, due to system settings, or anything else that is not directly entered in that row.
However, you should not be using calculated fields anyway. See http://allenbrowne.com/casu-14.html, among many posts advocating for not using calculated fields.
Instead, use queries to do calculations. That way, you won't have any trouble using the current date, and won't have to deal with the possible errors and portability issues calculated fields come with.
I changed my thinking to calculate this in a form. It does not seem good practice to have a field in a DB that changes everyday.
In a form, you can use this expression as controlsource for a textbox:
=DateDiff("yyyy",Date(),[EndDate])
However, that return the difference in calendar years. To find the count of full years, use a function like AgeSimple and this expression:
=AgeSimple([EndDate])

How to get the sum directly with one number?

I'm a beginner for tableau. I want to get the direct numbers for each row, but i get the number which are separate, how can i achieve this?
I've tried the sentence like:count("Implemented"), but I don't get the result I want.
For example, for the 1st row I want 3 10 10
not 111 10 112111111
Here is worksheet.
My code:
EDIT :
here is the photo for implementation opportunities
As you can see, the status is related to the date, I think maybe it causes the records which are counted 1by1.
Now the situation is that: i create the code which is related to the date, if i remove this from mark, it will cause the problem (the code is related to the date), but if i leave it, the system will always count it one by one. My code is not perfect but i can't find another one which can replace it.....
EDIT 2:
in short,what i want is the sum of the remaining opportunity:10
capture
Remove DAY from Mark shelf. That detail is producing those separations.
Attaching a workbook with numbers similar to (but not exact due to proprietary issues) is almost always advised. You will get the right answer a lot sooner than just screenshots.
In any case, it seems as if the measure portion of the visualization is properly being summed by the date. Try selecting the measure, and manually selecting "sum" from the menu drop down. Here is a link for more detail.
Secondly, you can play around with table calculations. Click this link and read up on option 3.

SUMIFS with multiple criteria, one of which is a single day

I'm trying to get a formula that will break down the amount of times a user enters a contest each day.
I'm pretty new to this whole thing, basically putting it together using google to figure out the code I need to use/modify. Explaining why something works would be greatly appreciated so I can use it elsewhere!
Here's a dummy of the form I'm banging my head against.
I would like the form to be reusable, so on the Sorted form I have a date key that automatically fills out the week when you choose the first day. Because of this, I would like each formula to refer to this date key, instead of manually typing the google equivalent of 'February 1st, 2015' into the formula.
I've tried to use the SUMIFS formula, and I've run in to a few errors.
Apparently both pages have to be the same amount of rows, otherwise I get an 'Array arguments to SUMIFS are of different size'. I didn't want my 'sorted' sheet to be 1761 rows long, since all of the duplicate names will have been condensed and I wanted it prettier. Nuts to that! Guess I can hide the rows? Is there any other solution?
It looks like this works:
=SUMIFS(Entered!E3:E1000, Sorted!E3:E1000, Sorted!$E3, Entered!A3:A1000, date(Sorted!$C7))
Where entered!E: is the number of entries, sortedE: is the list of usernames, and E3 is the specific one I'm looking for. Then EnteredA3 is the list of dates and time, and Sorted!C7 is the specific date I'm looking for. I don't get any results!
If I click on my C7 and sorted!A, the little calender pops up, which means they are dates (I think?). One includes the hours:minutes:seconds and the other doesn't, which I think is my problem. I would like to have sorted!C7 be the entire day, and filter out all of those entries.
This is taking information entered via a google form which I won't have control of, so I can't really change the H:M:S additions to the date column.
Thinking ahead to day 2 and onwards, will the same formula work when sorted!C10 is C$7$+1? Is it not a date anymore?
I would also like to add up the amount of daily entries, in sorted!S7 and below. I've tried wrapping both the column of dates and the date from my day key in the date() thing, but it doesn't seem to work either.
=SUMIF(date(Entered!A3:A),date(Sorted!C7),Entered!E3:E)
It gives me a '1', and I have no idea where that comes from.
I haven't been able to find much about the google SUMIFS function, mostly how to replicate it from before it was a thing.
And for even MORE complexity:
I was wondering if it is possible to have UNIQUE find the IDs in entered!C, and return all the associated usernames. That pesky angelo changed their username to 'pants' midway through the contest, and I'd like to be able to see both names and add up both 'angelo' and 'pants' entries in the same line in my formulas.
I feel like I'll need a few hidden columns that have the UNIQUE ID number and the associated usernames that I pull into my Sorted!Username column, but I don't know how to search the IDs to find the different usernames.
I tried to google that, but I have no idea what I'm googling.
Whewph! That is a lot of questions, thanks for any help!
Too long for my taste, but you might try:
=sumifs(Entered!E:E,Entered!A:A,">="&$C$7,Entered!A:A,"<"&$C$7+1,Entered!B:B,$E3)
in Sorted!F3 and copied down to suit.
Oh my goodness, you are a hero!
My final code wound up being:
=IF(ISBLANK(Sorted!$E3)=TRUE, "", sumifs('Entered'!$E:$E,'Entered'!$A:$A,">="&$C$7,'Entered'!$A:$A,"<"&$C$7+1,'Entered'!$B:$B,$E3))
I changed the start and end points by making $C$7 into $C$7+1, and the ending one into +2. (In case anyone else is looking at this answer.)
I'm super pleased that it worked!
Using this I managed to add up each of the daily entries, just by adding up the columns they were in.
I gave up on the UNIQUE idea, if someone changes their username during the contest, then they can add up the two rows themselves.
Thanks again! I'd upvote you, but I can't yet.

Tableau calculated field dates

I was trying to do a calculated field and I cannot get it to work right.
First I tried to duplicate what I did in access...
=DateDiff("d",[90 Days to Exp],[Expiration])
but that gives me an error
I did some research and found something that gave me valid calculations...
window_sum(datediff('day',
lookup(min([90 Days to Exp]), 0),
min([Expiration])))
that only shows 90 days which I already knew
I want to make sure it is doing a count down of days to "Expiration" so I changed it to...
window_sum(datediff('day',
lookup(min(NOW()), 0),
min([Expiration])))
also tried....
window_count(datediff('day',
lookup(min(NOW()), 0),
min([Expiration])))
still a valid calc but the numbers are way off.... I tried min and max with and without... and I still can't seem to get an accurate count down
Step back. Instead of giving us random pieces of code, explain what you're trying to achieve (what you expect as a result) and what your db looks like (for instance, what are the fields).
I'll give a solution to what I think you're trying to achieve on what I think you have as database.
I believe you have a database that each entry is a product that have an expiration date ([Expiration]). What I think you're trying to achieve is to know how many days are left until expiration date.
So, if you want to calculate this for each entry in your database, the formula should be:
DATEDIFF('day',NOW(),[Expiration])
It's very straight forward, you're calculating how many days there are between today and expiration date
I have no idea why you're using table calculations in your suggestions, but if this calculations should not be done for each entry (but rather for a collection of entries), then table calculations can be useful, but it's impossible to suggest anything if I don't understand precisely what you want