How to select an active record based on date range using from and to dates - date-range

A person may be placed at multiple locations throughout their life. The table used to store this information have from and to dates. Their current location will have a start date but NULL as the end date. All earlier placements will have a start and and end date.
The business then ask me to provide the name of the location they were at for a particular date, how would I write the sql to find the correct period and get the right location name?
I'm not sure how to proceed.
In this example, I am told the date to find the placement name for 13/03/2019.
The correct result would be: Overseas.
If I was given a date of 18/01/2011, then it would be city
cg_placementstartdate cg_placementenddate Placement Name
2011-01-17 00:00:00.000 2011-09-19 00:00:00.000 City
2011-04-12 00:00:00.000 2011-04-20 00:00:00.000 State
2011-09-19 00:00:00.000 NULL Overseas

Related

Can someone provide the logic for "selecting all the birthdays that occured within the last 90 days"? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 months ago.
Improve this question
edited*
I'm currently using Microsoft Power BI
Can someone provide the logic for "selecting all the birthdays that occured within the last 90 days relative to today's date"?
For example:
I have a table called "ClientTable" with the birthdays of 100 clients in an MM/DD/YYYY format. Today's date is 09/15/2022. I now want to list out all the of the clients that had a birthday within the last 90 days. So essentially, I am looking for a list of all the clients that had a birthday between 06/15/2022 and 09/15/2022.
This is how I attempted to solve it:
I first parsed out the Month and Day components of the BirthDate field into two separate columns. I then created a new table called "MasterDay" with all the dates in a single year and also parsed out the Month and Date components into separate columns:
MasterDate
Date
Month
Day
DD/MM/YYYY
MM
DD
DD/MM/YYYY
MM
DD
ClientTable
BirthDate
Month
Day
ClientID
DD/MM/YYYY
MM
DD
85
DD/MM/YYYY
MM
DD
7
I then created a relationship between the two tables "ClientTable" and "MasterDay" on their respective month and day columns. So that when placing the complete "Date" column from the MasterDay table into a slicer it would select all the corresponding rows from the "BirthDate" column in ClientDate table.
The issue I'm having is that when slicing for a range that begins in the middle of a particular month, say between 06/15/2022 and 09/15/2022, it picks up all of the birthdates in the months of June and September like 06/07/2022 or 09/23/2022 despite it not being included in the slicing range.
Thanks, G
In Power BI you would simply use a Relative Date Slicer or Filter.

How to find difference between two column in excel pivot

I have a column in power pivot named "member_status" which contains the status of a member as "Joiner"and "Leaver". I have another column called Date which has join date and leave date. I wan't to see how many left how many joined and the difference between two in a pivot table. Can any one please guide to what i wants to achieve please.
Table structure.
Status Date
Joiner 2017-11-31 00:00:00.000
Leaver 2017-09-30 00:00:00.000
Joiner 2017-02-11 00:00:00.000
Joiner 2017-03-26 00:00:00.000
Leaver 2017-10-31 00:00:00.000

Excel countif integer but exclude date value

I have a basic Excel file to log healthcare survey completed each week, identified by its Project ID, city, type of facility, date completed, and person assigned.
For the week of 10/02/17, I just want to count the number of projects completed that starts in the 17000s; ignore projects in the 1000s.
For example, week of 10/02/17, North zone, =COUNTIF(H3:L9,">17000") = 11. My expected result is 4 not 11 as I want to exclude the date values from the count. See image screenshot for clarification. Thanks
=COUNTIF(H3:L9,">17000")
simply edit your countif statement to exclude the rest of the cells.
=COUNTIF(H3:H9, ">17000")

Get closest date based on matching mutiple criteria in Excel

I have two tabs as below in Excel:
Table 1:
Date Vehicle Number Planned Leave Time Actual Leave Time
8/7/2017 10001 8/7/17 4:59 AM
Table 2:
Date Vehicle Number Actual Leave Time
8/7/2017 10001 8/7/17 4:29 AM
8/7/2017 10001 8/7/17 5:59 AM
8/7/2017 10001 8/6/17 3:05 PM
8/7/2017 10003 8/6/17 2:05 PM
I want to get the actual leave time from table 2 based on matching the same date, same vehicle number between table 1 and table 2;
Also, as you can see, there are multiple records for a same vehicle and same date in table 2, so I think I have to compare the time (8/7/17 4:59 AM) to all the time in table 2 that on 8/7/2017 and for vehicle 10001, to get the closest time, which has the minimum abs difference between my planned time and active time.
So can anyone please tell me what formula I should use in Excel in order to achieve my purpose?
Thanks so much
Pudge
I turned your data tables into Tables and used structured references, so it doesn't really matter where your tables are located. In addition, the formulas and references will automatically update if you add rows to either table. Also, you can rename the tables to something meaningful, if you like.
The formula is an array formula so must be entered by holding down ctrl+shift while hitting enter. If you do this correctly, Excel will place braces {...} around the formula:
=INDEX(Table2[Actual Leave Time], MATCH(MIN(ABS(([#Date]=Table2[Date])*([#[Vehicle Number]]=Table2[Vehicle Number])*Table2[Actual Leave Time]-[#[Planned Leave Time]])),ABS(([#Date]=Table2[Date])*([#[Vehicle Number]]=Table2[Vehicle Number])*Table2[Actual Leave Time]-[#[Planned Leave Time]]),0))

Calculate most recent payment date from multiple rows of payment information in excel

My data are in the following format:
This information is regarding accounts that have been outsourced to a collection agency. As you can see, we have multiple rows for each agency, and multiple rows for each date in which those accounts were withdrawn and assigned. For example, the first agency, Bob Agency, was assigned on 3/12/15, withdrawn on 6/12/15, and assigned to Carla Agency on 6/30/15. Each agency is shown in a different column, and the first two corresponding columns in "Agency Date" refer to their assignment and withdrawl. If the cells are blank, that means that the accounts have not been withdrawn/assigned respectively.
I want to calculate the difference in days between when the account is assigned to any given agency, and the date of the most recent assignment. So using the previous example, the difference between 6/30/15 and 3/12/15.
My problem is that I can't work around the blank dates. Some accounts have multiple assignments and withdrawals, and others have just one.
Thank you for your help!
Assuming column L is empty, place this formula there:
=IF(MAX(G2:K2)=0,TODAY()-F2,MAX(G2:K2)-F2)
It will calculate the most recent assignment date and subtract it from the initial date. If no re-assignment date is there, it will use today's date.

Resources