calculate hours between 2 timestamps using excel pivot table - excel

i have a table like this:
user | sg_message_id | event | datetime
--------------------------------------------------------------------------------
john player | ekjf939e9313140_34k | delivered | 04/13/2018 12:56:30
john player | ekjf939e9313140_34k | opened | 04/15/2018 16:05:00
cristian dior | dsfsk0340344030fkjkj | delivered | 04/12/2018 18:45:21
cristian dior | dsfsk0340344030fkjkj | opened | 04/13/2018 15:40:17
For a user, for each unique sg_message_id, how do i create an Excel pivot table that can display hours elapsed between when an email was delivered and when it was opened?

You can use Calculated Item... in your pivot table. If your data set is not that big. Follow this steps:
You can use Power Query. It is an add-in developed by Microsoft since Excel2010+ (by default in Excel2016 known as Get and Transform). There you can connect directly any type of source of data and edit it as you want.
Here an example for your case:

Related

Excel Pivot values as column labels

I am trying to create a Dependent drop-down list in excel using data from a pivot table.
The source data looks like this:
+--------+---------+
| Name | Country |
+--------+---------+
| John | USA |
| Albery | USA |
| Mary | Canada |
| Bob | Canada |
| Alice | Mexico |
+--------+---------+
Using Pivot I am able to fetch the data dynamical in a similar setup. However, in order to create a dependent drop-down lists for an Entire Column like like in this tutorial. I need the pivot to dynamically display data like this:
+--------+--------+--------+
| Canada | Mexico | USA |
+--------+--------+--------+
| Bob | Alice | Albery |
| Mary | | John |
+--------+--------+--------+
Is this even possible using pivot, or is there any other way to achieve this?
Attached Excel file
If you have Excel for Office 365 (or Excel 2021) with the FILTER function, you can use the following:
Note that I used a table with structured references for the data source. This has advantages in editing the table in the future
For "pivot" header:
=TRANSPOSE(SORT(UNIQUE(Table1[Country])))
For the columns:
F2: =FILTER(Table1[[Name]:[Name]],Table1[[Country]:[Country]]=F$1)
and fill across. The results in Columns F:H will SPILL down.
If you don't have those functions, you can pivot text using Power Query, available in Windows Excel 2010+ and Microsoft 365

MS Excel: How to list all column if the rows contain a given date?

My data looks like below. I have Groups that I share topics each day. We do this randomly based on need.
| | Topic 1 | Topic 2 | Topic 3 | Topic 4 | Topic 5 | Topic 6 | Topic 7 | Topic 8 | Topic 9 |
|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|
| Group 1 | | 19-apr | 30-apr | | | | | | |
| Group 2 | 18-apr | 25-apr | | | | | | | |
| Group 3 | | | | | 19-apr | 30-apr | | | |
| Group 4 | 18-apr | 25-apr | | | | | | | |
| Group 5 | | | | | | | 19-apr | 30-apr | |
| Group 6 | | | 25-apr | | | | | | |
| Group 7 | 18-apr | 25-apr | | | | | | | |
For our metrics & analysis, we need a list of groups per date on a different sheet. We like to know which all groups were engaged a given day. Like below
Can somebody please help me how I can get this done with only using formulas and without macros?
I believe this can somehow be handled on Index Matching or look-ups.
You could definitely do this with macros. You can do something similar without macros; it may not be precisely what you were looking for because it will leave blank space where groups were not addressed.
Method 1
Here is the formula I used and a picture of the sheet it is in:
=IF(IFERROR(MATCH(L$4,$B6:$H6,0),FALSE),INDEX($B$5:$B$13,MATCH($K5,$B$5:$B$13,0),1),"")
The idea is that if you have absolute references alongside your list of groups per date, then you can use index and match to fill in that group's name, but only if Match finds that precise date code in that group's row from the previous table. If you place an equivalent formula in the first cell, you can drag it out to the rest of the array.
The formula I used is not the only way to do this, but if you know Index and Match, then it should make sense to you.
Method 2
A more convoluted method would be to use image references. With these, it is possible to make the report precisely what you asked for on a separate sheet.
Suppose you took Method 1 and separated each column out into a different table. Nearly the same formula inside the cells below the date heading, except that you enclose the heading reference in int() as shown below. Create one table for each of N dates, where N is the number of days you want to monitor at once. Then when you want the summary to show you different dates, you go to each table and change the heading, and filter out blanks.
formula:
=IF(IFERROR(MATCH(INT($L$2),$B4:$H4,1),FALSE),INDEX($B$4:$B$11,MATCH($K3,$B$4:$B$11,1),0),"")
The below image shows what I mean by one table for each date:
Then you insert an image. Doesn't matter what image; could be a screenshot of anything. Click on that image, then click into the formula bar. Then highlight the table column you want it to represent. Below is a screenshot of how to to that:
Now place that picture on its own sheet in the workbook. Place each date table on its own sheet in the workbook. The reason you do this is: if you filter a table, everything else overlapping the filtered rows outside the table will also be hidden. You move tables to separate sheets to prevent them from hiding each other.
Finally, arrange your pictures into the order you like, filter the blanks out of the tables, and your images will be exactly what you were looking for:
Again, this is a little convoluted because if you want the report to show you new date summaries, you would have to change the headings on every table. Then you would have to go to each table and refresh it's filter. This is where macros usually come in.
Assume range A1:J8 housed your Source table, and L1:P8 housed the Date/Group Output
1] In L2, copied across :
=IFERROR(1/(1/AGGREGATE(15,6,$B$2:$J$8/($B$2:$J$8>K$2),1)),"")
2] In L3, copied across to P3 and all copied down :
=IF(L$2="","",IFERROR(INDEX($A:$A,AGGREGATE(15,6,ROW($A$2:$A$8)/($B$2:$J$8=L$2),ROW(A1))),""))
You can use the following formula to get a list of dates from a table:
=IFERROR(AGGREGATE(15,6,($B$2:$J$8/($B$2:$J$8*(COUNTIF($A$15:A15,$B$2:$J$8)=0)))*$B$2:$J$8,1),"")
To get a list of groups by date, use the following:
=IFERROR(INDEX($A$1:$A$8,AGGREGATE(15,6,(1/(B$15=$B$1:$J$8))*ROW($B$1:$J$8),ROW(A1))),"")

How to return datetime in Excel when SQL table has only time?

I am currently querying against an Informix SQL table that is datetime, however only holds time, such as "07:30:44". I need to be able to pull this data and have the send_time show what the actual time was, and not "0:00:00".
Example:
Informix Table Data
--------------------------
| send_date | 02/09/2016 | --datetime field
--------------------------
| send_time | 07:30:44 | --datetime field
--------------------------
When I query through Excel via Microsoft Query editor, I can see the correct value, "07:30:44" in the preview, however what is returned in my sheet is "0:00:00". Normally I would change the formatting on the cell, however the literal value for the entire column is "12:00:00 AM".
Excel pulls/displays
--------------------------
| send_date | 02/09/2016 |
--------------------------
| send_time | 12:00:00 AM| --displayed is "0:00:00"
--------------------------
I have cast the field as char to see if it would return correctly, and it does! However you can't use parameters/build quick reports with this method.
Desired Excel output
--------------------------
| send_date | 02/09/2016 |
--------------------------
| send_time | 07:30:44 |
--------------------------
Is there another way to resolve this? I'd love to give the users an easy way to build queries without having to cast anything.

CSV file always picks the lowest price

Hi I am using Magento and an extension called matrix rates, they use .CSV files to store the data for the post codes saying what post code has what delivery charge. The problem I have got is that it only picks the smallest delivery charge for every single postcode when it should look at the rate for the post code first and then if there isn't one pick the flat rate. I was just wondering if anybody has any ideas.
My excel sheet is like this>>
Country | Region/State | City | Zip/Postal Code From |Zip/Postal Code To | Weight From | Weight To | Shipping Price | Delivery Type
GBR | * | - | - | 0 | 9999 | 9999 | Websales Shipping (WS01)
GBR | * | - | - | AB37% | 0 | 9999 | 65 | Websales Shipping (WS01)
Without more details, your pseudo-code (or, pseudo-formula) could look like this:
=if(
vlookup([postCode], [PostCodeShipRateTable], [rateColumn]) >0,
[postcodeRate],
[flatRate]
)
[flatRate] could also be a vlookup to another rate table if nec.

How to present/organize repetitive data contained in cells in excel?

Would there be a better way to present/organize repetitive data contained in cells in excel? I've provided a set of sample data below (I can't show my actual records for confidentiality reasons) just so that you guys could visualize the data.
Country | Type | Company | Department | Project | Currency | Amount
USA | Restaurant | Bob's Barbeque | Sanitation | Monthly Sanitation | Records Database | USD | 100
USA | Restaurant | Bob's Barbeque | Human Resources | Staff Timesheet USD | 203
USA | Restaurant | Bob's Barbeque | Human Resources | Email Portal for Employees | USD | 259
USA | Manufacturing | Duff Autos | Research and Development | Inventory System| USD | 234
USA | Manufacturing | Duff Autos | Sales | Inventory System | USD | 654
China | Manufacturing | Weihua Electronics | Research and Development | Inventory System | RMB | 102
China | Government | Department of Tourism | Advertisement | Billboard Design and Deployment Web Portal | RMB | 2044
As you can see, it contains a lot of repetitive data like the "Country" and the "Type". It may look organized as it is but it looks cluttered as the data multiplies. I've thought this thoroughly over the past few days but I still can't figure out a way to do organize it such that it would look pretty.
I've tried Excel's filter functionality, sorting, and others but I still think it looks cluttered. Any suggestions? Thanks!
Pivot the data, then you can open and close the sections as you please. I just did it on your sample, then in the resulting pivot tick all the fields, drag the amount one from row labels to values then click on the little down arrow and choose value field settings.
Select Sum and press OK.
the + and - on the data in the pivot allows you to fold open and close the fields to make it look however you like.

Resources