How to find difference between two column in excel pivot - excel

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

Related

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

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

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))

For a certain date interval in a pivot table, check for each row in a power pivot table if it overlaps

I have a list of employees together with the dates that they started and the days that they quit:
Name Started Quit
Liza 2014-01-01 2014-07-18
Erik 2003-01-01
John 2007-02-05 2015-02-12
Sigurd 2012-02-20
Ivo 2014-01-01 2014-12-31
In a pivot table, for any filtered date interval I want to see the number of people that have been working at least one day in that interval.
So if I would choose 2014-12-31 - Any time in the pivot table, I would get:
Erik
John
Sigurd
Ivo
How can I create this behavior using a Power Pivot data model?
Ideas for possible solution:
I imagine that I would create either some kind of calculated field for this or maybe a new junction table with the headers Name, Month, Working (boolean). But I don't know.
You could do with adding a measure that takes account of the blanks in your "quit" column:
[Lasteffectivedate]:=IF(ISBLANK(LASTDATE(Employees[Quit])),TODAY(),LASTDATE(Employees[Quit]))
Then you can add another measure that determines if the employee was active on the selected date or dates:
[IsActive]:=CALCULATE(COUNTROWS(Employees),FILTER('Employees',firstdate(Employees[Started])<=LASTDATE('Date Table'[Date])),FILTER('Employees',[Lasteffectivedate]>=FIRSTDATE('Date Table'[Date])))
This assumes that you have a disconnected date table which is used as the source for your date selection.

Need to group Time Slots in Excel

I am working on logistics data. I have booking being made throughout the day at regular intervals from start to the end of the day.
Now these booking are consistent and I have time from like
04:45
21:10
21:10
06:07
05:44
05:45
05:45
05:45
etc.
Now as there are multiple bookings I need to group them such as
04:00- 05:00 (1 hours)- this should capture all booking made during this period.
Similar for other hours during the day.
By doing this I will be able to group individual values into specific group. Can you please advice how to achieve the same in excel.
If the values are stored as dates in Excel, the Pivot Table has this functionality built in already with the "Group Field" option. You can group by Hours which is probably what you want. Note that you can select multiple items to get a hierarchy of groups as shown below. This will break if the underlying data is not formatted as a Date so watch out for that.
If you do not have true dates and just have times, you can format as a Time in Excel and it will work. Just don't show the days/date because it will be gibberish.
add a column truncating the time to hours
along the lines of =time(hour(z),0,0)
then create a pivot table using the hour column

Powerpivot: Joining historicals for database and forecast from a calculated linked table in a single pivottable

I noticed a few people have tried to do similar things that I am asking below. I may have a suggestion in my answer as to how I fix it so i'll ask the question first.
I have historical data that I source from a datawarehouse connection and load into Powerpivot:
Date Store Sales NumTransactions Tag
2010-01-01 A 20000 50 Historical
2010-01-01 B 15000 10 Historical
2010-01-01 C 5000 3 Historical
2010-01-01 D 300000 500 Historical
That connection to Powerpivot is a direct connection to the database server.
And from this data, i calculate a forecast, within excel that spits out a table that is then brought into PowerPivot using a linked table.
Date Store Sales NumTransactions Tag
2010-01-02 A 20010 51 Forecast
2010-01-02 B 16000 12 Forecast
2010-01-02 C 6000 5 Forecast
2010-01-02 D 400000 650 Forecast
From this I want to be able to drive a number of pivot tables and charts which show both sets of data together:
Date Store Sales NumTransactions Tag
2010-01-01 A 20000 50 Historical
2010-01-01 B 15000 10 Historical
2010-01-01 C 5000 3 Historical
2010-01-01 D 300000 500 Historical
2010-01-02 A 20010 51 Forecast
2010-01-02 B 16000 12 Forecast
2010-01-02 C 6000 5 Forecast
2010-01-02 D 400000 650 Forecast
How do i make this happen? I cant seem to make a relationship work as there is multiple dates and multiple store records.
I have tried to join the two together at within Powerpivot in Table Properties -> Query Editor:
SELECT [daily].* FROM [daily]
UNION ALL
SELECT [fcst].* from [fcst]
(Where [daily] is the historical data from the datawarehouse and [fcst] is the linked table within the excel workbook that has been linked into powerpivot)
But the problem is that Powerpivot is looking for [fcst] from the Connection that goes back to the datawarehouse where my historicals are coming from.
I can make a work around of driving two pivot tables out of the two data sources and then link them together into one table in excel by directly referencing the cells of the pivot tables (and then drive charts off that). But its messy, and Im sure this can be done. I just cant figure out how.
Does the answer lie in a Set defined by MDX?
Any ideas would be greatly appreciated.
Thanks!
When PowerPivot creates a relationship, it needs one table to have a column with distinct values that you use as a lookup column for another table. I would suggest that you create a date table. You can get one from https://datamarket.azure.com/dataset/1542c52d-d466-4094-a801-9ef8fd7c6485 if you don't have an easy way to create one. Then you can create a relationship from daily to date and from fcst to date. I would also add a calculated column to daily with just a string "Historical" and add a calculated column to fcst for a string "Forecast". Add another linked table with two rows in it: Historical, Forecast. Then create a relationship from daily to this linked table. If you create a flattened PivotTable with all this in place - you can get close to what you're looking for, but you're probably going to have one column for sales for historical and another column for sales for forecast. You can create a measure in one of the tables (doesn't matter which one) to use conditional logic to use the applicable value based on the current tag and just use that in your PivotTable instead. Do the same for the number of transactions.
You can also add a table of month end dates that is not linked to any other tables and use that date as a slicer with Dates equal to or less than the Slicer, select Actuals and Dates greater than the Slicer, use the Forecast. In doing this you avoid picking up a partial month of actuals for an incomplete month. Then add a measure such as...
calculate(sum(historical[sales], filter(historical[date]<=max(monthend[Dates]))) + calculate(sum(forecast[sales], filter(forecast[sales]> max(monthend[Dates])))

Resources