Sep 05 2024 07:02 AM
Greetings, We’re continuing our series of posts to show you some of the things that are possible to do with Copilot in Excel. Today I have a table that shows all of the employee travel for my team coming up. I would like to get a total count of people traveling.
I ask Copilot the following to help me answer my question:
Add a column to calculate the number of people travelling based on the Person(s) Traveling column
Looking at K2:L17, here's 1 formula column to review and insert in Column M:
Number of People
Counts the number of people traveling by identifying and summing the occurrences of delimiters such as "+", ";", and "," in the "Person(s) Traveling" column, then adding 1 (person) to account for the first person listed.
=SUM(LEN([@[Person(s) Traveling]])-LEN(SUBSTITUTE([@[Person(s) Traveling]],"+","")),LEN([@[Person(s) Traveling]])-LEN(SUBSTITUTE([@[Person(s) Traveling]],";","")),LEN([@[Person(s) Traveling]])-LEN(SUBSTITUTE([@[Person(s) Traveling]],",","")))+1
I hover over the Insert Column button to see how it will calculate the results. With a quick spot check, I see that the numbers look right except for the 2nd row that uses a slash as a delimiter.
Since the formula doesn’t calculate all of the rows correctly, I prompt Copilot again with the following:
That looks mostly right, please update to also use the / as a delimiter
Looking at K2:L17, here's 1 formula column to review and insert in Column M:
Number of People
Counts the number of people traveling by identifying and removing common delimiters such as "+", ";", ",", and "/" from the "Person(s) Traveling" entries, then calculating the difference in length to determine the number of individuals listed.
=LEN([@[Person(s) Traveling]])-LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE([@[Person(s) Traveling]],"+",""),";",""),",",""),"/",""))+1
The updated formula looks correct. After clicking on the Insert Column command, I get the following table:
Over the coming weeks I will be sharing more examples of what you can do with Copilot in Excel.
Thanks for reading,
Microsoft Excel Team
*Disclaimer: If you try these types of prompts and they do not work as expected, it is most likely due to our gradual feature rollout process. Please try again in a few weeks.
Sep 05 2024 08:26 AM
I re-created your table in Excel because I was curious what formula Copilot would suggest. I used the same wording for the prompt, too.
Copilot suggested:
=COUNTA(
FILTERXML(
"<t><s>" &
SUBSTITUTE(
SUBSTITUTE(
SUBSTITUTE([@[Person(s) Traveling]], ",", "</s><s>"),
";",
"</s><s>"
),
"+",
"</s><s>"
) & "</s></t>",
"//s"
)
)
A more direct solution would be:
=LET(
split, TEXTSPLIT([@[Person(s) Traveling]], {"+", "/", ";", ","}),
COUNTA(split)
)