Compare Dates in a column corresponding to Changes in an other row - sql

I have a large sample of medical data I need to try and analyze patterns in Excel worksheet.
I also put them up in a database in MS ACCESS to do my first filters and stuff.
I have the infos of patients, with tests results(POS or NEG), dates of the sample.
I need to be able to check for each patients when the results change from POS to NEG and from NEG to POS
and compare the dates of those two samples.
So far I was doing it manually which isn't viable for my sample.
I was trying to do something in SQL, but that didn't work out for me.
I also am trying to do some VBA or Excel formulas but I admit I'm getting kind of stumped.
I know I should do some for each cell loop or something but I really am lost.
I already grouped each patients info together using sub-totals and stuff.
Your help or at least pointers would be greatly appreciated :D
Here's an example of my data.
enter image description here

Use a formula like this, that in case the name is the same as the row before and the POS/NEG is different from the row before gives you the number of days in between, blank otherwise:
Of course it will give you an error if you try to use it on the 1st line, just enter it in the 2nd line and copy/paste in all the rest.
This should give you the basis for the rest of your analysis.

Related

VBA challenge: Spent a while with VBA, just messing this up more

So I'm in a rush to put together an excel file for something quick and dirty at work. I've spent several days learning VBA / macros and have learned many individual pieces needed for this, but putting them all together is just not working how I'm looking for.
So I'm taking something similar to the following table of data and trying to reorganize it:
(I can't post the image bc of rep)
![Sample Data Table] https://imgur.com/a/FrwEp
Data in columns d-f are all a list of stuff. What I want to do is start with the first date in column D, find the range of where it fits in column a and copy the data there. For an expense report for example - e1:f1 data would get copied over to b1:c1 since it corresponds with that as the date range. In a nutshell, dates in column A are income dates. They are set to pay all items listed on the right scheduled to be paid before the next pay date. See the finished example here:
![Final Sample Data Table] https://imgur.com/a/niaqB
How might you throw this together to make it work. I'm looking for simplicity as I'm gonna have to heavily modify it to what its actually being applied to.
Sorry for the weird post, this is my first time creating a post myself :)
A handy way to get started with VBA is to record a macro of the actions you need to duplicate, and then analyze the macro's generated VBA code, line by line, revising the code to fit your needs.
(Also: Using Comparison Operators in VBA)

Excel Macro to combine cells of data when data matches in another column

The best way I can explain my problem is by showing a few screenshots.
I need to turn data like this:
[
Into something that displays like this:
After Data
There are multiple part numbers in the file, and I need the macro to take all the data from a matching part number and transform the data into what is displayed in the second image. All the part numbers are grouped with their data together, so it wouldn't need to run the loop through the top every single time, but adding to the entries with each new piece of data. Something also needs to be done for the years as well, because the way the data is presented, is in a range of years, and I need an entry for each year in that range.
Additional Information:
I am using this data for prep for category data for a BigCommerce site, that is working with a year/make/model plugin on the site, to create a vehicle lookup system. Thus in order for the user to look up their vehicle accurately the categories need to be listed the way they are in the second picture, which needs to be the result of the macro.
I thank anyone who takes the time to look into this, it will cut down the time I spend doing this manually by a huge amount.
You can do this with a formula (without actual VBA):
In cell F2 write: ="YMM/"&C2&"/"&D2&"/"&E2&";"
In cell F3 write: =F2&"YMM/"&C3&"/"&D3&"/"&E3&";"
drag down the formula in F3 until the last row.
The last row will contain the entire string of all vehicles.
I just noticed you may have duplicate values. You can use the built in Remove Duplicates feature to remove those before using the above technique.

Query several ranges and add automatically a column to know the source of each row

I am trying to achieve the following in Google Spreadsheets.
First, I want to query several ranges (in different sheets from the same spreadsheet). I tried a formula like this =query(arrayformula({indirect(E2:E10)}),"select * where Col1 <>''") with no success
In E2:E10 I have a list of ranges. Column F contains a name that describes the source of the value in Column E.
My second problem is that I need to add a column to the output of that query that tells me the origin of each row.
If the sources are ranges of 3 columns by country I need to merge those tables and add that country to each row.
All credits to +Ben Liebrand who helped me out here: https://support.google.com/docs/profile/3464
"I just want to start of by saying that the indirect() function does not work in an arrayformula() function as expected. So you will need to take another approach. I can understand what you are trying to do so I added another TAB in your spreadsheet to demonstrate another approach. I know it was initially a specific design you were trying so I made some changes to what you had. Maybe you can take a look at what I have offered and maybe you can tweak your design.
I know what I am offering is just very rough but you will also notice that I removed the end row specifier from your ranges in the range table.
Don't assume my example to be the final result but I was just trying to show that the range you were trying to use with the indirect() function will not work.
So hopefully this will give you a new idea of how you can maybe handle this.
My formula also adds the country to each of the tables in the output. My formula looks like this
=query(ArrayFormula({
if(len(indirect(regexextract(F2,"\w+\!\w+")&":A")),G2,),indirect(F2);
if(len(indirect(regexextract(F3,"\w+\!\w+")&":A")),G3,),indirect(F3);
if(len(indirect(regexextract(F4,"\w+\!\w+")&":A")),G4,),indirect(F4);
if(len(indirect(regexextract(F5,"\w+\!\w+")&":A")),G5,),indirect(F5);
if(len(indirect(regexextract(F6,"\w+\!\w+")&":A")),G6,),indirect(F6);
if(len(indirect(regexextract(F7,"\w+\!\w+")&":A")),G7,),indirect(F7)
})," select * where Col1 <> '' ")
Hope this is of some help to you"
And I hope is useful to the community
GerĂ³nimo

Netsuite - Saved Search with Days Calculation Formula

![enter image description here][1]I am trying to create a Saved Search in Netsuite that calculates the number of days between two dates in a summarized search. I am attaching a screenshot of the Results tab for reference. I have tried using a Numeric Formula field, as well as a Date/Time Formula field. I have also tried every Summary Type available. Is there another way to do this? I just get an entire blank column when I run this.
As some background, I am trying to calculate how many days between when the system note was changed to Pending Accounting to when the system note was changed to Processed.
Thanks!
Update: It won't let me upload photos. Here is the formula I am using:
(CASE WHEN {systemnotes.newvalue}
= 'Processed'THEN {systemnotes.date} END)-(CASE WHEN {systemnotes.newvalue}
='Pending Accounting'THEN {systemnotes.date} END)
I'm not sure you are going to be able to evaluate this.
systemnotes.value can only have one value at each cell, which means that you can't have it be equal to Processed and Pending Accounting at the same time.
What you do in this case is something along the lines of
CASE WHEN {systemnotes.newvalue}= 'Processed'
THEN TO_DATE({systemnotes.date})
ELSEIF {systemnotes.newvalue}='Pending Accounting'
THEN TO_DATE({systemnotes.date})*-1
ELSE 0
END
And then do a sum on the whole thing. I'm pretty sure this won't work as this is not tested, but the idea is to declare on each cell the positive, negative or null value, and then add make NS add the whole column to summarise.
Also you might find issues for duplicate values so if the state goes back to a previous state you might get weird results.
Edit- see if you can find something to work with unix time, that might make life easier.
See reference for oracle sql: http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions001.htm

Pull data from multiple Excel sheets, count how many of a certain lead within a month

A continuation of a previous question... where I have run into another formula issue.
We have an Excel spreadsheet where we track our leads. My boss wants to know, specifically "how many leads for each month and how many of each source and the result."
The users on this forum were incredibly helpful, and gtwebb gave me this formula (thank you!):
=COUNTIF(Sheet1!A14:A21,12012)
Which worked beautifully for counting how many leads we had in each month.
Now I need to know how many leads came from the Web, SOI, VP/Sign, etc., WITHIN that month. So I'm hoping there is a formula where I can ask Excel to only look at a certain month, say 12012, and then how many leads we got from the Web or other places. I know I'll need to change our lead source for each formula, but I can't get the basic formula to work. I've tried: =countif(Sheet1!e2:e20,12012, if(Sheet1!m2:m20,Web)), and other variations on this, trying to elaborate on the original formula that worked correctly.
Thank you for your help!
A Pivot Table didn't really ring a bell with me, so I looked into a formula solution.
Pnuts posted a suggestion to try sumifs(). I could only get this to work if there was a column with "1" in it for every line.
A similar function, countifs(), seems to work. Here's a formula for counting the number of lines with a month of "12012" and a source of "Web":
=COUNTIFS(Sheet1!A:A,"=12012",Sheet1!B:B,"=Web")
It assumes that column A is month and column B is source. Good luck!
Your boss wants a Pivot Table made from the data. Unless you have other reasons for using formulas or VBA (not stated in the question), using the pivot table functionality instead will save you a lot of effort in this case.