简体   繁体   中英

excel formula with multiple criteria (match and index?)

I have a table with following structure and it shows calendar entries:

|     Title     |  Description  |   StartTime   |    EndTime    |      User      |

表格1 .

I want to create a new table with the following structure and this table would show all users and their plans for the date which has given in the first row.:

|    User    |  Date1  |  Date2  |  Date3  |  …

表2 .

My problem is something like this:

I want to show in the second table the titles of the rows if the Date1(or Date2 ..) is between Start- and End date. So I need an excel formula which I can write in all cells.

.

I could write a SQL statement like that (I know its syntax is not correct but I want to show what I need):

SELECT Title 
FROM Table1, Table2 
WHERE Date1 > StartDate AND Date1 < EndDate and User.Table1 = User.Table2

.............

Can you please help me?

Can't think of a simple way to do this.

First of all, how do you plan to display it if there are two titles that fall under the same date segment for the same user?

To me this looks like an effort to reverse engineer a summary table to a more detailed table, in which you will need to type in the individual column by dates - fill in all the missing data, then a simple pivot would do the job.

First you will need to keep only ONE date field, then populate all the dates in between start and end date.

From this: *listing two titles - a and b for user ak to illustrate the problem where one user has multiple titles appearing within the same date segment.

在此处输入图片说明

To this: - populating all the dates where the title will appear

在此处输入图片说明

Then just pivot the new range to get this: 在此处输入图片说明

Instead of the title being listed out, we can see which date did it occur. Easily copy and paste the pivot as values, then replace the title count "1" with title name "a" to get below: 在此处输入图片说明

Assuming you would want the title concatenated by user, just copy the blue part, and get the end result below: 在此处输入图片说明

Do you have Power Query? if you have Excel 2016 version you have it (Get & Transform) in previous versions you can download it. it is a free add-in.

  1. Go to Data
  2. Select From Table/Range
  3. ok

It will appear the Query Editor, there you can:

  1. Change data type to "Date"

  1. Go to Add Column
  2. And 7. In date options select "Subtract Days"

  1. Fix the negatives results Duration.Days([End] - [Start])

  1. Add a "custom column" List.Dates([Start],[Subtraction]+1,#duration(1,0,0,0))

  1. Click in the corner (doble arrow) and chose "Expand to New Rows"

  1. Select and delete Columns that you won't need

  1. Go to Transform
  2. Click "Pivot Column"
  3. In "Advanced Options" select "Don't aggregate"
  4. ok
  5. Go Home select "close & load"

Finally you get a new sheet with the new information.

You can add some filters to see a specific period of time...

The amazing thing about this is you can append all the data that you want, and then it will be a simple right click and refresh in the green table, and you will have your data fixed it.

This is the query if you just want to copy and paste in the "Advanced Editor"

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Title", type text}, {"Start", type date}, {"End", type date}, {"User", type text}}),
    #"Inserted Date Subtraction" = Table.AddColumn(#"Changed Type", "Subtraction", each Duration.Days([End] - [Start])),
    #"Added Custom" = Table.AddColumn(#"Inserted Date Subtraction", "Days", each List.Dates([Start],[Subtraction]+1,#duration(1,0,0,0))),
    #"Expanded Days" = Table.ExpandListColumn(#"Added Custom", "Days"),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Days",{"Start", "End", "Subtraction"}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Removed Columns", {{"Days", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Removed Columns", {{"Days", type text}}, "en-US")[Days]), "Days", "Title")
in
    #"Pivoted Column"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM