My input data table looks like this
ID AdmitDate
ABC001 1/1/2017
XYZ007 1/2/2017
XYZ002 1/3/2017
ABC001 1/4/2017
ABC001 1/7/2017
XYZ002 1/7/2017
And I am trying to retrieve previous admit date for each new visit. The output should be something like this.
ID AdmitDate PreviousAdmitDate
ABC001 1/1/2017
XYZ007 1/2/2017
XYZ002 1/3/2017
ABC001 1/4/2017 1/1/2017
ABC001 1/7/2017 1/4/2017
XYZ002 1/7/2017 1/3/2017
In SQL I would have done something like...
LAG(AdmitDate, 1, Null) OVER (PARTITION BY ID ORDER BY AdmitDate) AS PreviousAdmitDate
I tried the below solution from this post but didn't work.
First([AdmitDate]) OVER (Intersect([ID], Previous([AdmitDate])))
What would be the Spotfire custom expression way of doing it?
#WeShall - Here are the steps:
Step 1: Add a calculated column which has decreasing counts of ID's.
Count([ID]) over (intersect([ID],AllNext([AdmitDate])))
Step 2: Now, using the calculated column from the previous step, add a calculated column which shows the previous date of the same ID.
Min([AdmitDate]) over (Intersect([ID],Next([decreasing_count])))
Note: The column 'decreasing_count' can work in the background. It is not necessary to display it in the table.
Final Output table:
Hope this helps.
Related
I have a spreadsheet that contains data for customers that have purchased items from my store. What I would like to do is go back the last couple years, using a pivot table, and display: number of customers that ordered something each month (a count of unique customer names).
The sheet is organized as such:
Date | Invoice | Account Name | Item | Quantity | Amount
6/1/2020 | 50100 | John's Tire Shop | 1/2 Inch Socket | 2 | 12.00
Is there a way inside pivot table options to count unique account names and display the total grouped by month?
You can create a helper column to identify unique values per month to add as a filter to your pivot using your existing setup
=IF(COUNTIFS($A$2:A2,A2,$B$2:B2,B2)=1,"y","n")
I would propose you to add a helper column to your data, containing the =Month(A:A) function. But be careful: I see that your first date equals "6/1/2020", is that the first of June or is this Epiphany? :-)
i have two tables
one includes dates (table1)
Date
11/10/2019
11/17/2019
the other one has names (table2)
Name Surname
xxxxxx
yyyyyy
i want to combine the second table for each data in the table1
result should be
Name Surname Date
xxxxxx 11/10/2019
yyyyyy 11/10/2019
xxxxxx 11/17/2019
yyyyyy 11/17/2019
i am sure it is very for you guys,
thanks for the help,
It's quite easy:
= Table.Join(table2,{},table1,{})
I have following data in Excel:
Name, Status, Date
Name is name of Book and combination Name, Date is unique.
Status is one of 4 possible statuses
In stock
Ordered
Rented
Missing
Date is date of entry
Data are entered every week and they like this:
Name, Status, Date
ABCD, In Stock, 1/1/2017
BCDE, Ordered, 1/1/2017
CDEF, Rented, 1/1/2017
DEFG, Rented, 1/1/2017
ABCD, In Stock, 10/1/2017
BCDE, In Stock, 10/1/2017
CDEF, In Stock, 10/1/2017
ABCD, IN Stock, 20/1/2017
BCDE, Rented, 20/1/2017
CDEF, Rented, 20/1/2017
EFGH, Ordered, 20/1/2017
What I need to find are few thinks:
how many entries were added each date and how many removed?
which books have same status for all Dates (or selected dates using slicer)
Is it possible to do such things using pivots? Or do I need different tool?
You can put pivot tables:
1. For book status by date Columns: Status, Rows: Date, Values: Count of Name
For Unique Status all dates: Columns: Name, Rows: Date, Values Count of Status.
Then you can just look at the sum for each column - which ever has 1 - thats the book you are looking for.
Hope it helps.
I have an Excel sheet set up basically with the first two columns as a person's name and their ID. Then the rest of the columns are title of a skill. The values of the table are basically the skill levels (0-4). So it looks like:
| Name | ID | Skill 1 | Skill 2|
| Jane | 01 | 3 | 4 |
I was wondering how I can use pivot tables to make it so that I have a column where I can I select in the dropdown the "Skill" and in that column would be 0, 1, 2, 3, 4 then the column next to it shows the Count of how many people put 0 for that skill etc.
Right now I have it like that but only one skill and if I wanted to change to a different skill, I have to manually change the pivot table row label. I was hoping to just change it within the pivot table itself.
I could rearrange the data to make this work but I'm having trouble conceptualizing how the data should be organized for this.
Is this doable in Excel?
Normally for pivot tables you want the data in a format more like this
Name ID Skill# Skill Value
Jane 01 1 3
Jane 01 2 4
Then you would be able to show what you want in the pivot table. You could then use report filters or column labels (with filters) to only show skill# 1 or skill#2.
I have been melting my brain trying to work out the formula i need for a multiple conditional lookup.
I have two data sets, one is job data and the other is contract data.
The job data contains customer name, location of job and date of job. I need to find out if the job was contracted when it took place, and if it was return a value from column N in the contract data.
The problem comes when i try to use the date ranges, as there are frequently more than one contract per customer.
So for example, in my job data:-
CUSTOMER | LOCATION | JOB DATE
Cust A | Port A | 01/01/2014
Cust A | Port B | 01/02/2014
Customer A had a contract in port B that expired on 21st Feb 2014, so here i would want it to return the value from column N in my contract data as the job was under contract.
Customer A did not have a contract in port A at the time of the job, so i would want it to return 'no contract'.
Contract data has columns containing customer name, port name, and a start and end date value, as well as my lookup category.
I think i need to be using index / match but i can't seem to get them to work with my date ranges. Is there another type of lookup i can use to get this to work?
Please help, I'm losing the plot!
Thanks :)
You can use two approaches here:
In both result and source tables make a helper column that concatenates all three values like this: =A2&B2&C2. So that you get something like 'Cust APort A01/01/2014'. That is, you get a unique value by which you can identify the row. You can add delimiter if needed: =A2&"|"&B2&"|"&C2. Then you can perform VLOOKUP by this value.
You can add a helper column with row number (1, 2, 3 ...) in source table. Then you can use =SUMIFS(<row_number_column>,<source_condition_column_1>,<condition_1>,<source_condition_column_2>,<condition_2>,...) to return the row number of source table that matches all three conditions. You can use this row number to perform INDEX or whatever is needed. But BE CAREFUL: check that there are only unique combinations of all three columns in source table, otherwise this approach may return wrong results. I.e. if matching conditions are met in rows 3 and 7 it will return 10 which is completely wrong.