Finds the last instance of a substring in a text and returns its index.
LASTINDEXOF(text, substring)
text is what you are looking at.
substring is what you are searching for in text.
Example:
If A1 contains "Hello" and A2 contains "l":
LASTINDEXOF(A1, A2)
returns 3
Text:
Substring:
Result:
Analyzing Website User Data
Imagine you are a data analyst for an e-commerce website. You have a log of user actions, and you want to find the last time a specific user viewed a product page. This could be useful for a variety of reasons, such as:
Let's say your data is stored in a simple array of strings, where each string represents a sequence of user actions for a single session.
The following table shows a log of actions for a user named "Alice". Each entry in the Session Actions column is a string representing the pages she visited, in order.
Session ID | User | Session Actions | ||
|---|---|---|---|---|
A | B | C | ||
1 | 101 | Alice | homepage,category,productA,cart | |
2 | 102 | Alice | homepage,search,productB,productA | |
3 | 103 | Alice | homepage,category,productC,productA,productB,checkout | |
4 | 104 | Alice | homepage,productA,productA |
Your goal is to find the last time the string "productA" appears in each session's action log. The LASTINDEXOF function is perfect for this. It returns the index of the last occurrence of a specified substring within a string. If the substring is not found, it returns -1.
Let's apply LASTINDEXOF to the "Session Actions" for each session.
Here is the updated table, showing the result of the LASTINDEXOF function for each session.
Session ID | User | Session Actions | LASTINDEXOF("productA") | ||
|---|---|---|---|---|---|
A | B | C | D | ||
1 | 101 | Alice | homepage,category,productA,cart | 18 | |
2 | 102 | Alice | homepage,search,productB,productA | 25 | |
3 | 103 | Alice | homepage,category,productC,productA,productB,checkout | 27 | |
4 | 104 | Alice | homepage,productA,productA | 18 |
PRODUCT & FEATURES
RESOURCES
Terms | Privacy | Spam Policy
© 2026 Zapof