Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
KeithSP
Regular Visitor

Sub String lookup for Multiple Values contained in a cell.

I have two queries.  One query contains a list of users with one value (Approved by) per row.  I have another query that lists more than one value in the cell (Approvers).  The values are separated by a delimiter.  I want to look up to see if the Approved By is listed in the Approver report, with a simple yes no result.  For example, if this was excel it would be IF(Approver By = "*"Approver"*", "Yes","No")

 

TIA

1 REPLY 1
rbriga
Impactful Individual
Impactful Individual

Let's solve this in the query.

Take the second query, use a function to seperate the "approved by" list into rows.

Then inner join this table with the users table.

In SQL, this can be:

Now, inner join this table with the users table. 

WITH _List AS
(
SELECT [ID], value AS [Approved By]
FROM [YourTable]
CROSS APPLY STRING_SPLIT([Approved By], ',')
),

_Valid_Approvers AS
(
SELECT
_List.ID,
COUNT(*) AS Approvers_Count
FROM _List
INNER JOIN [ApproversTable] AT
ON AT.Approver = _List.Approver
GROUP BY _List.ID
)

SELECT
[YourTable].*,
CASE
WHEN VA.Approvers_Count IS NULL THEN 'No',
ELSE 'YES'
END AS Has_Valid_Approvers
FROM [YourTable] C
LEFT JOIN _Valid_Approvers VA
ON C.[ID] = VA.[ID]

 

-------------------------
Data analyst by day, hockey goalie by night.
Did I help? Then please hit that "kudos" or "accept as a solution" button!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.