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
Anonymous
Not applicable

Split column by comma delimiter in some and no comma in others

Hello

 

I have a DirectQuery connection to a SQL server database.  I have a column that could have from 1 to 2 to 3, max, entries in them delimited by comma.  I need to separate the anwsers and then put them into one column.  But they can have a range of answers, meaning it can be:

 

Answer1

Answer1,Answer2

Answer1,Answer2,Answer3

 

It can be any types of these.  Hard to grab the first answer type becuase there is no comma to search off.  Please advise.  Thanks

1 ACCEPTED SOLUTION

See this post...  I think you're going to have to get someone to help you write your SQL input as a SQL Statement instead of just using the DirectQuery default option.  

 

https://community.powerbi.com/t5/Desktop/Create-a-query-to-select-data-from-a-table/td-p/26581

 

Building your own SQL Statement will give you more flexability in your aquisition of the data from the Database (resolving your commas issues).  You will just have to find a SQL programmer to assist you...

 

FOrrest




Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




View solution in original post

12 REPLIES 12
fhill
Resident Rockstar
Resident Rockstar

See if this works!

 

Raw data matching example:

Capture.PNG

 

Select the Answer column and choose Advanced options under 'Split Coulmn"  You want ROWS instead of coulmns.

Capture2.PNG

 

Final Result:

Capture3.PNG




Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




Anonymous
Not applicable

thanks fhill, I am not ble to get to the raw data, it is a direct query from SQL server.  Thanks for the idea.

See if this works using "New Table" command under 'Modeling".

 

Break your coulmn up into 3 coulns using...

Ans_1 = PATHITEM(SUBSTITUTE(Table2[Answer1],",","|"),1)

Ans_2 = PATHITEM(SUBSTITUTE(Table2[Answer1],",","|"),2)

Ans_3 = PATHITEM(SUBSTITUTE(Table2[Answer1],",","|"),3) 

 

 

NewTable = UNION(
SELECTCOLUMNS( Table2, "T",Table2[Ans_1],"Name",Table2[Name],"Date",Table2[Date]),
SELECTCOLUMNS(Table2, "T", Table2[Ans_2],"Name",Table2[Name],"Date",Table2[Date]),
SELECTCOLUMNS(Table2, "T", Table2[Ans_3],"Name",Table2[Name],"Date",Table2[Date])
)

 

Capture.PNG




Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




Anonymous
Not applicable

Sorry fhill, I do not have the New Table option, since I am in DirectQuery.

Also shows error for the first step as PATHITEM is not able to be used in DirectQuery models.

 

Another great idea to try but not in my current mode.

 

Anonymous
Not applicable

I can et the one with one answer pulled out, I can get the second one with 2 answers pulled out, but I can not get the third.  I am having trouble with MID or RIGHT or SEARCH or FIND.  Once I get them pulled I am not certain how I am oing to get them all in one column.  Thanks in advance for any and all help.

....  In this mode, are you using SQL statments to pull the data from the database directly by chance...?




Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




Anonymous
Not applicable

I am using the fields directly.  Not certain I know what you mean.  Sorry.

Anonymous
Not applicable

Trying to think of other ways around this.  Still with the DirectQuery pull, I was looking at SUBSTITUTE and thinking I can sub first , with one thing and second with something else and do a LEFT and search for it and go from there.  I was able to do a nested SUB as a test but when I try to add the last option of the function tells me SUB not in DirectQuery.  Is there a DirectQuery option for SUB or REPLACE?  Thanks

 

See this post...  I think you're going to have to get someone to help you write your SQL input as a SQL Statement instead of just using the DirectQuery default option.  

 

https://community.powerbi.com/t5/Desktop/Create-a-query-to-select-data-from-a-table/td-p/26581

 

Building your own SQL Statement will give you more flexability in your aquisition of the data from the Database (resolving your commas issues).  You will just have to find a SQL programmer to assist you...

 

FOrrest




Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




Anonymous
Not applicable

Thank you Forrest.  I am going to give this a look and see what I can try and figure out from here and leave the post open for now.  Thanks

Hi @Anonymous,

There are some limitations for Direct query Mode, you can see the limitations part in this article. It's good to try SQL statement to filter data from SQL Datebase. Please feel free to ask if you have any problem related to Power BI.

Best Regards,
Angelia

fhill
Resident Rockstar
Resident Rockstar

....  P.S.   I just tried inserting the 'PATHITHEM(SUBSITUTE... commands directly into the UNION(SELECTCOLUMNS( and that works too if you want to hit it in one blow...

 

FOrrest




Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




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.