Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi everyone
I have a field in my SQL database that shows a field called Type_ with a set of numbers separated by a comma for several million record e.g.
Is it possible to add a column / measure that says "if the field Type_ contains 15742000 then show this as A and if the field contains / also contains 154720004 then show this as B)? So, in this example we would show A, B in stead of 15472000, 154720004. There are many of these numbers and therefore literally thousands of combinations, otherwise I would create a lookup table and link that.
Any help would be much appreciated.
Many thanks
Jon
Solved! Go to Solution.
Hi @jonclay ,
This may not be the best way. But you can try something like this.
Create a Calculated Column
Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)
@jonclay what is the RDMBMS? Is it MSSQL?
If there is no filter context involved in this, I would strongly suggest you to do this transformation server side for a million row table. An example in TSQL with a lookup table
DECLARE @fact AS TABLE
(
rownum INT,
descr VARCHAR (40)
)
INSERT INTO @fact
SELECT *
FROM (VALUES(1,
'email,phone'),
(2,
'email,phone,pager'),
(3,
'fax,computer')) t(a, b)
DECLARE @lookup AS TABLE
(
_name VARCHAR(10),
_altname VARCHAR(10)
)
INSERT INTO @lookup
SELECT *
FROM (VALUES('email',
'e'),
('phone',
'p1'),
('pager',
'p2'),
('fax',
'f'),
('computer',
'c')) t(a, b);
WITH cte1
AS (SELECT rownum,
x.value AS _splitValue,
z._altname
FROM @fact
CROSS apply String_split(descr, ',')x
CROSS apply (SELECT y.*
FROM @lookup y
WHERE x.value = y._name)z)
SELECT a1.*,
x.plc
FROM @fact a1
CROSS apply(SELECT *
FROM (SELECT rownum,
Stuff((SELECT ',' + _altname
FROM cte1 a
WHERE a.rownum = b.rownum
FOR xml path ('')), 1, 1, '') AS plc
FROM cte1 b
GROUP BY rownum) a2
WHERE a1.rownum = a2.rownum) x
From here
to
Hi @jonclay ,
This may not be the best way. But you can try something like this.
Create a Calculated Column
Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)
@jonclay in this example your new value will be B since all the rows contain both the values, correct?
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
@parry2k Many thanks for your reply. No, the field can contain any number of different values e.g. 15470000, 15470001, 15470002 and so on.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
80 | |
79 | |
60 | |
36 | |
33 |
User | Count |
---|---|
91 | |
59 | |
59 | |
49 | |
42 |