Excel单元格多日期拆分:按固定日期列添加对应X标记
Got it, let's tackle this Excel transformation problem. Here are two straightforward methods to get your desired output—one using formulas (perfect for quick, one-off tasks) and another with Power Query (ideal if you need to refresh the data regularly):
Method 1: Using Excel Formulas
This is the fastest way for a static dataset:
- First, set up your output table with the fixed headers:
姓名(Name),工作日(Work Days),1,2,3,4,5,6,7 - For the first date column (e.g., cell C2 under header
1), paste this formula:=IF(ISNUMBER(SEARCH(C$1,$B2)),"X","")- Quick breakdown:
SEARCH(C$1,$B2)checks if the header value (like "1") exists in the comma-separated list in column B.ISNUMBERconverts the search result to a yes/no boolean, andIFoutputs "X" if found, otherwise an empty string.
- Quick breakdown:
- Drag the formula across all 7 date columns, then drag it down to apply to every row. Your table will populate with "X" marks exactly where needed.
Method 2: Using Power Query (For Automated/Refreshable Results)
Use this if your source data might change and you want to avoid redoing formulas:
- Select your original data table, go to the
Datatab >From Table/Range(make sure your data has headers). - In the Power Query Editor:
- Go to
Add Column>Custom Column, create a column that splits the workday values into a list:
Rename this column to= Text.Split([工作日(Work Days)], ",")Work Day List. - Add custom columns for each date 1-7. For example, for date
1:
Repeat this for dates 2 through 7, updating the string in the formula each time.= if List.Contains([Work Day List], "1") then "X" else "" - Optional: Delete the
Work Day Listcolumn if you don't need it anymore.
- Go to
- Click
Close & Loadto bring the transformed table back to Excel. Right-click the table later and selectRefreshif your source data changes.
Final Output Example
| 姓名(Name) | 工作日(Work Days) | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|---|
| Person 1 | 2,3,5 | X | X | X | ||||
| Person 2 | 1,2 | X | X | |||||
| Person 3 | 5 | X | ||||||
| Person 4 | 1,2,3,6,7 | X | X | X | X | X |
内容的提问来源于stack exchange,提问作者Kilo64
相关产品推荐
相关产品推荐

