Excel Forumla/VBA to skip blank columns for calculation - vba

I have a particular data set that consists of information for projects our company works on. Each project can go through five different statuses and we have a column that records each date the project is put into that particular status.
Now for the Excel part. We are trying to calculate the days in each status and find the total project time. The total is easy to do, because I can use network days between the project submitted date and the project go live date. The statuses, however, are giving me issues because sometimes a project will skip a status, leaving the date field empty. So what happens is a project goes from status B to status D, the formula for days in status "B" look for a date in column "C" to use as the second date in a NETWORKDAYS formula. When it is empty, the IF argument tells the formula to use TODAY() as the second date. What I need it to do is the search the columns to the right (within the given range of A:E for that row) and use that date if it exists. If not, then it can default to TODAY() because this would be an "active" project that has not moved on.
=IF(IF(OR([#STALLED]<>"",[#CANCELED]<>""),"",IF([#INTAKEDATE]="","",IF([#SCOPEATE]="",NETWORKDAYS([#INTAKEDATE],TODAY()),(NETWORKDAYS([#STATUSADATE],[#SCOPEATE])))))<0,"",(IF(OR([#STALLED]<>"",[#CANCELED]<>""),"",IF([#INTAKEDATE]="","",IF([#SCOPEATE]="",NETWORKDAYS([#INTAKEDATE],TODAY()),(NETWORKDAYS([#STATUSADATE],[#SCOPEATE])))))))
This is done for each of the statuses so the table looks something like this:
PROJECTID PROJECTNAME INTAKEDATE SCOPEATE BUILDDATE TESTDATE GOLIVEDATE INTAKEDAYS SCOPEDAYS BUILDDAYS TESTDAYS
If there is any Macro or better formula someone could help me figure out, I'd appreciate it. There is also another field that gives the current status or if the project is considered live if that helps at all. I have excel-block right now and cant think of anything that makes sense for this.

So I figured it out using MIN and by adjusting the IF formulas a bit. Whoever it was that posted about MAX earlier, really helped me out getting me down this path. Kudos to you sir/madam.
I had to add the check to see if SCOPEDATE=BUILDDATE because without that it was returning 1 if the dates matched, with was adding one more day when compared to running the networkdays from INTAKEDATE to GOLIVEDATE.
=IF(OR([#STALLED]<>"",[#CANCELED]<>""),"",
IF([#SCOPEDATE]="","",
IF([#SCOPEDATE]=[#BUILDDATE],0,
IF(NETWORKDAYS([#SCOPEDATE],(MIN([#BUILDDATE],[#TESTDATE],[#GOLIVEDATE])))<0,NETWORKDAYS([#SCOPEDATE],TODAY()),NETWORKDAYS([#SCOPEDATE],(MIN([#BUILDDATE],[#TESTDATE],[#GOLIVEDATE])))))))
I hope this is helpful for someone else.

Related

Is there another way in Qlik Sense to show the latest weeks data by default as well as a filter to change the week you're looking at?

I am looking to add a weekly filter onto my Qlik dashboard to allow me to change the weekly data that is displayed on my dashboard. My original idea works well as I wanted to display the latest weeks data and compare this to the previous weeks and this gives me exactly what I want.
To enhance this and give the dashboard a bit more flexibility and just in case someone wanted to look at a different week, I thought it might be a good idea to add a weekly filter but the way I have built the dashboard won't allow me to do this. The following is an example of what I have:
In my database table I have a rank column (latest_week_rank) where the latest weekending (i.e. Mon 13th to Sun 19th Jan) has a value of 1 and the 2nd latest week would be 2 etc. I have then written the following code in my data tab:
latest_week = 1;
previous_week = 2;
I have then written the following which is then called within a Multi KPI:
vOrdersWTD =Sum({<latest_week_rank = {$(latest_week)}>} total_orders)
This is obviously where the problem lies as having the weekly filter makes no difference as no other weeks show up but I am not sure how I change my code in order to make this all work.
I would really appreciate if somebody could advise on how I can change this around.
Instead of assigning your predetermined variable in set analysis, use the actual field. Something like:
$(=
'Sum({<latest_week_rank = {'
& max(latest_week_rank)+1
& '}>} total_orders'
)

Get Difference in Dates Over Time SQL/Excel

I am trying to get a date difference to determine cycle time of when something arrives to completion. However, I need the product to count towards cycle time average for all days it is here. So, something along the lines if arrivdate='8/16' but completiondate='8/24', I need for the cycle time for this product to be 1 on '8/17', 2 on '8/18', etc until it is 8 on '8/24' and then stops counting. I am willing to do it in either Excel or SQL, if there is a fast way to do it. Below is an example of the data in an Excel sheet
https://drive.google.com/open?id=0B4xYGwf8uS7ZdE5YRDYzXzNuOTQ is a link to the file, as I'm not sure how to insert a table in here.
Does this suit?
If I understand your question properly this simple formula should work. You can replace the 0 with "" to leave it blank

Access 2013: How to Return All Records With Date Older than X?

My Problem
I have a date field in the table in question. I'm trying to create a query that will only display records where that date field are 120 days old or older.
My Code
Solution Attempt 1
The first solution I tried was simply added criteria to my date field. The criteria formula I used was:
< Date()-120
This removed a few 'random' records leaving me with 714 of my original 905 records. Unfortunately, a quick look through the dates of remaining records in ascending order, it was obvious that I was still getting records more recent that 120 days old.
Based on my 'random' result above, I double checked the format of my field by changing the field to:
DATE: Format([myDtField], "mm/dd/yyyy")
I ran the query again - this reduced the number of records removed, leaving me with 734 of 905 - but my issue persisted - I still had records with dates more recent than 120 old.
Solution Attempt 2
Based on my issues above, I decided to go a different route. This time I created a unique field for my criteria calculation. For the field value I used:
DateDiff: DateDiff("d",[myDtField],Date())
This resulted in values that were very far off from the correct values (ex. a record with a date of yesterday resulted in 43!).
Solution Attempt 3
This was less of a solution and more just troubleshooting, but based on the results I'm getting, I keep thinking my dates aren't being perceived by the system as the date it's displaying (i.e. DateValue() is off compared to displayed value). I spot checked a few of the dates vs their DateValue() and the randomly selected records all seemed to be correct. So again, no luck.
Solution Attempt 4
#Gustov reminded me about the DateValue() function. I've attempted that on the field as well - the field is imported as a text field, thus needs converted to a date value. Similar to the formula Gustov posted, for my field value I used:
DATEDIFF: DateDiff("d",Nz(DateValue([LASTPAYDT]),0),Date())
And then in the criteria I simply used the formula:
>120
This results in the following error:
Data type mismatch in criteria expression
This was probably the closest solution I had, simply because WITHOUT criteria it returns the proper values (i.e. a date of yesterday returned "1", while a date of two days ago returned "2"... etc). So you would think simply limiting records where this field is >120 would work, but then it throws up the error above.
My Question
Does anyone have an idea of how to check if a record field is 120
days old or older?
If either of my above solutions works for question 1, then what might be wrong with my date field that is causing issues if I am going about it the right way?
#Gustov's DateValue() solution is close (i.e. provides the correct values), but adding criteria causes an error. Any solutions?
I'm at a loss. An extra set of eyes on this problem would be greatly appreciated. Thanks!
Hans touches something. If the dates are not dates but text, try this:
Select * From YourTable
Where
IsDate([myDtField])
And
DateDiff("d", DateValue([myDtField]), Date()) > 120
I have tried this and it works, DATAText is the data stored as a text.
SELECT Tabella1.ID, Tabella1.DATAText, Date() AS Espr1
FROM Tabella1
WHERE (cDate(Format(Tabella1.DataText,"yyyy-MM-dd hh:mm:ss")))<Date()-120;

Update log table with data from the log table

Due to recent updates to the recent database, I have run into a weird problem. I have two tables, tVehicleDeal table and tVehicleLog table. We did a 'migration' meaning we created an app that will transfer the data from a old database to a more relational database. This process took awhile, but it finished and everything seemed good to go. What happens now, is that anytime tVehicleDeal is updated, the corresponding information is inserted into tVehicleLog. The problem that has occurred is.. I ran a script that would update the current deal in tVehicleDeal to the most recent log in tVehicleLog. I made an error in my script, and not all the current deals in tVehicleDeal were updated properly. As a result, when the users updated the active deal in tVehicleDeal, not all the information was inserted into the tVehicleLog. I need to find a way to update the newest entry with some fields from the past entries such as the date it was titled. Some Deals have as many as 20 different logs for it whereas some may have only 2 or 3. I have found this link here but I'm not 100 percent positive this is what I'm looking for. I have tried something similar to this but I am unable to get anything to work using the examples found on that page. Any other ideas will help greatly!
EDIT:
What I am unable to figure out is how to update a column in tVehicleLog. For example:
In the tVehicleLog table there are 6 results for a particular DealID.
The first through 4 do not have a titled date in it, but the 5th row does have a titled date.
I can't figure out how to update the titled column the 6th row for that dealID based on the 5th row that does have the titled date.
The link provided above looked like it was something I was looking for but I was unable to get that solution to work.
Based on this line from your question,
I can't figure out how to update the titled column the 6th row for
that dealID based on the 5th row that does have the titled date.
It seems like this should fix your problem. It is written only to solve this specific scenario. If other scenarios exist that are not exactly like this one, adjustments may have to be made. If I didn't understand your problem, please post further clarification.
UPDATE L1
SET TitleDate=L2.TitleDate
FROM tVehicleLog L1
INNER JOIN tVehicleLog L2
ON L1.DealID=L2.DealID
AND L2.TitleDate IS NOT NULL
WHERE L1.<PrimaryKeyColumn>=#ThePrimaryKeyColumnOfTheRowYouWantToUpdate

pulling current date queue

I have a view that lists employee (EmpID), request number (ReqNo), date request was opened (OpenDate) and the date it was moved to the next step in the process (AssignDate). What I am trying to do is get an average of the daily queue size. If EmpID 001 has 20 requests on 1/1/13, then has 24 on 1/2/13, 21 on 1/3/13 the average over 3 days should be 21.66, rounded up to 22. I have the following view:
CREATE VIEW EmpReqs
AS
SELECT [EmpID], [OpenDate], [AssignDate], [ReqID]
FROM [Metrics].[dbo].[Assignments]
WHERE OpenDate BETWEEN '01/01/2013' AND '12/31/2013' AND
[EmpID] IS NOT NULL AND
[ReqNo] NOT LIKE 'M%'
I then wrote a query to pull individual employee's queues per day:
/* First attempt to generate daily queue #s */
SELECT * FROM BLReqs
WHERE [BusLiaison] LIKE 'PN' AND
[OpenDate] <= '11/15/2013' AND
[AssignDate] > '11/15/2013'
Because no one has attempted to pull this information before, I have no way of verifying how accurate the above is. I tried using current dates, since I can see those in our database to compare but the code doesn't work, nothing is returned when I change the dates to 2014 and run my query.
What is the easiest way to verify that my code is correct, short of manually counting a day's queue?
Can anyone see any issues with the above scripts?
Is there a way to get the above code to work with current dates?
This question is really hard to answer because it is kind of broad and has little information at the same time. I'll try anyway:
Because no one has attempted to pull this information before, I have
no way of verifying how accurate the above is.
Try checking the result of this query for a few sampled dates.
I tried using current dates, since I can see those in our database to
compare but the code doesn't work, nothing is returned when I change
the dates to 2014 and run my query.
So clearly, the query is not working. You should probably find out why. Run the query for a date of which you know that it should return results but doesn't. Remove conditions one by one to see which one is incorrectly removing all rows. This should be enough to identify the bug.
Can anyone see any issues with the above scripts?
No, looks fine. A very simple query. That's why I said that we have too little information. There is some key piece of information missing that allows us to find the bug.
Is there a way to get the above code to work with current dates?
Stop staring at the code and hoping for a revelation. Debug it. Experiment.