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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ShubhamBarnwal
Frequent Visitor

Creating table using search

Please help in suggesting a solution.
I want to create a Resulting Table that takes an identifier (ID) from Main Table and maps the relevant columns from Secondary Table based on search in ID column.

Secondary table can have any number of rows but the Resulting Table must have IDs from Main Table only.

Thanks in advance!

 

Main Table ID
  123
  456
  789
  246
  135
  234

 

Secondary Table IDCommentDate
  123,234Test129-Jan-20
  135Test226-Jan-20
  123/789Test323-Jan-20
  456-135Test420-Jan-20
  246Test517-Jan-20

 

Resulting Table IDCommentDate
  123Test129-Jan-20
  123Test323-Jan-20
  456Test420-Jan-20
  789Test323-Jan-20
  246Test517-Jan-20
  135Test420-Jan-20
  135Test226-Jan-20
  234Test129-Jan-20
1 ACCEPTED SOLUTION

@ShubhamBarnwal  here you go !!! one thing - this can't be solved in DAX, DAX simply does not have the capacity to split a string based on number consecution.

 

 

//function qx
let
  fx=(a)=>
    Web.Page(
        "<script>
            x = '"&a&"';
            y=x.match(/\d+/gm)
            document.write(y);
        </script>"){0}[Data]{0}[Children]{1}[Children]{0}[Text]
             
    
    
in
    fx

 

 

main query - secondary table -ID split on consecutive numbers

 

let
    Source = Web.BrowserContents("https://community.powerbi.com/t5/Desktop/Creating-table-using-search/m-p/1632697#M656635"),
    #"Extracted Table From Html" = Html.Table(Source, {{"Column1", "TABLE:nth-child(7) > * > TR > :nth-child(1)"}, {"Column2", "TABLE:nth-child(7) > * > TR > :nth-child(2)"}, {"Column3", "TABLE:nth-child(7) > * > TR > :nth-child(3)"}, {"Column4", "TABLE:nth-child(7) > * > TR > :nth-child(4)"}, {"Column5", "TABLE:nth-child(7) > * > TR > :nth-child(5)"}}, [RowSelector="TABLE:nth-child(7) > * > TR"]),
    #"Promoted Headers" = Table.PromoteHeaders(#"Extracted Table From Html", [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Secondary Table", type text}, {"", type text}, {"ID", type text}, {"Comment", type text}, {"Date", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each qx([ID])),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each Text.Split([Custom],",")),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Custom"}),
    #"Expanded Custom.1" = Table.ExpandListColumn(#"Removed Columns", "Custom.1")
in
    #"Expanded Custom.1"

 

result

Capture.PNG

once you are up to here , you can merge this in pqwry or use dax...up to you.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

7 REPLIES 7
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
parry2k
Super User
Super User

@ShubhamBarnwal hmmm it is going to be complicated since there is no pattern as such. Not sure what to say, might be not something I'm going to spend time to solve since it is totally not a model-based approach. Good luck!



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
Super User
Super User

@ShubhamBarnwal I would recommend transforming secondary table by splitting id into rows, like splitting on all separator (/, - and comma) and then it will be super simple

 

Check my latest blog post Compare Budgeted Scenarios vs. Actuals I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



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 
I thought of that too. But Secondary Table ID column comes from a source that is a free text and can have random data in it too. Say "Entry for ID: 123". So i must specifically search for IDs that are in my Main Table.

@ShubhamBarnwalcan you spare some details on the ID column of the secondary and what string can it contain and what exactly do you want to extract from that string. E.g. is it goin to be a mixed value string from which you want to extract only consecutive numbers ? Please give some more example of the ID column values

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

@smpa01 
As mentioned, Secondary Table ID column is a free flow text field. We want to extract the info based on search for ID in Main Table.
And yes, secondary table ID column is a mixed value string and we have to search for 3 digit number in that. There can be multiple IDs (3 digit number) in one entry too.

 

Secondary Table IDCommentDate
  123,234Test129-Jan-20
  135Test226-Jan-20
  123/789Test323-Jan-20
  456-135Test420-Jan-20
  246Test517-Jan-20

@ShubhamBarnwal  here you go !!! one thing - this can't be solved in DAX, DAX simply does not have the capacity to split a string based on number consecution.

 

 

//function qx
let
  fx=(a)=>
    Web.Page(
        "<script>
            x = '"&a&"';
            y=x.match(/\d+/gm)
            document.write(y);
        </script>"){0}[Data]{0}[Children]{1}[Children]{0}[Text]
             
    
    
in
    fx

 

 

main query - secondary table -ID split on consecutive numbers

 

let
    Source = Web.BrowserContents("https://community.powerbi.com/t5/Desktop/Creating-table-using-search/m-p/1632697#M656635"),
    #"Extracted Table From Html" = Html.Table(Source, {{"Column1", "TABLE:nth-child(7) > * > TR > :nth-child(1)"}, {"Column2", "TABLE:nth-child(7) > * > TR > :nth-child(2)"}, {"Column3", "TABLE:nth-child(7) > * > TR > :nth-child(3)"}, {"Column4", "TABLE:nth-child(7) > * > TR > :nth-child(4)"}, {"Column5", "TABLE:nth-child(7) > * > TR > :nth-child(5)"}}, [RowSelector="TABLE:nth-child(7) > * > TR"]),
    #"Promoted Headers" = Table.PromoteHeaders(#"Extracted Table From Html", [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Secondary Table", type text}, {"", type text}, {"ID", type text}, {"Comment", type text}, {"Date", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each qx([ID])),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each Text.Split([Custom],",")),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Custom"}),
    #"Expanded Custom.1" = Table.ExpandListColumn(#"Removed Columns", "Custom.1")
in
    #"Expanded Custom.1"

 

result

Capture.PNG

once you are up to here , you can merge this in pqwry or use dax...up to you.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.