Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!
Hola a todos,
Puedo hacer esto en sql muy fácil, pero tengo que hacerlo en el editor de consultas power bi power con M.
(no DAX)
Hay una columna con los valores:
TABLA1. CODE_COLUMN
| XXYYZZTT |
| PPRRQQSS |
Y hay otra columna en otra tabla
TABLA2. DIRTY_DATA
| 123123XXYYZZTT123123 |
| XXYYZZTT44223xxxxxfdwe |
| dadfewrerXXYYZZTT987 |
| asdf324aerq |
| daf33421adf |
| 1PPRRQQSSr2d2 |
Tengo que buscar los primeros valores de columna uno por uno y cuando encuentro el valor, tengo que extraer el primer valor antes que él, sí mismo y siguiendo 3 caracteres con él.
Las nuevas 3 columnas serían:
| TABLA2. FETCH1 | TABLA2. FETCH2 | TABLA2. FETCH3 |
| 3 | XXYYZZTT | 123 |
| t | XXYYZZTT | 442 |
| r | XXYYZZTT | 987 |
| Null | Null | Null |
| Null | Null | Null |
| 1 | PPRRQQSS | R2d |
No puedo hacerlo con botones estándar:
Solved! Go to Solution.
Hola
He dividido el proceso en (esperemos) pasos digeribles (por favor, compruebe también el archivo adjunto):
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("NYo7DoAgEETvQm3DLol6C34FQihIFnqxwOOLKJPXzMwLgXHAjnPH4b21X+uwuAQ2VyEA8H5TqOVxUaKSW811Ovu2jiNdVBBEyvX8xYIogHd/dC6l1koZU4GAxfgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
ListOfFoundCodes = Table.AddColumn(#"Changed Type", "PositionOfText", each List.Transform(Table1_Code_Column[Column1], (x) => Text.PositionOf([Column1], x))),
IndexOfCode = Table.AddColumn(ListOfFoundCodes, "IndexFoundCode", each List.PositionOfAny([PositionOfText], {0..1000})),
PositionWithinDirtyData = Table.AddColumn(IndexOfCode, "PositionOfTextWhereFound", each List.Max([PositionOfText])),
Fetch1 = Table.AddColumn(PositionWithinDirtyData, "Fetch1", each try Text.Range([Column1],[PositionOfTextWhereFound]-1, 1) otherwise null),
Fetch2 = Table.AddColumn(Fetch1, "Fetch2", each if [IndexFoundCode] = -1 then null else Table1_Code_Column{[IndexFoundCode]}[Column1]),
Fetch3 = Table.AddColumn(Fetch2, "Fetch3", each if [IndexFoundCode] = -1 then null else Text.Range([Column1],[PositionOfTextWhereFound] + Text.Length([Fetch2]),3))
in
Fetch3
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Hola
He dividido el proceso en (esperemos) pasos digeribles (por favor, compruebe también el archivo adjunto):
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("NYo7DoAgEETvQm3DLol6C34FQihIFnqxwOOLKJPXzMwLgXHAjnPH4b21X+uwuAQ2VyEA8H5TqOVxUaKSW811Ovu2jiNdVBBEyvX8xYIogHd/dC6l1koZU4GAxfgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
ListOfFoundCodes = Table.AddColumn(#"Changed Type", "PositionOfText", each List.Transform(Table1_Code_Column[Column1], (x) => Text.PositionOf([Column1], x))),
IndexOfCode = Table.AddColumn(ListOfFoundCodes, "IndexFoundCode", each List.PositionOfAny([PositionOfText], {0..1000})),
PositionWithinDirtyData = Table.AddColumn(IndexOfCode, "PositionOfTextWhereFound", each List.Max([PositionOfText])),
Fetch1 = Table.AddColumn(PositionWithinDirtyData, "Fetch1", each try Text.Range([Column1],[PositionOfTextWhereFound]-1, 1) otherwise null),
Fetch2 = Table.AddColumn(Fetch1, "Fetch2", each if [IndexFoundCode] = -1 then null else Table1_Code_Column{[IndexFoundCode]}[Column1]),
Fetch3 = Table.AddColumn(Fetch2, "Fetch3", each if [IndexFoundCode] = -1 then null else Text.Range([Column1],[PositionOfTextWhereFound] + Text.Length([Fetch2]),3))
in
Fetch3
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Queridos @ImkeF ,
funciona como un encanto, muchas gracias.
Veo que mi conocimiento sql no ayuda en absoluto, parece tan complicado que no pude resolverlo por mi cuenta.
Hago todo en sql e intento familiarizarme con Power BI últimamente. ¿Qué fuente ofrecerías para poder escribir este código tuyo, porque los que estudié no ayudaron en absoluto?
y gracias @amitchandak!
Vote for your favorite vizzies from the Power BI World Championship submissions!
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
Check out the January 2026 Power BI update to learn about new features.