cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
kavitaTickoo Frequent Visitor
Frequent Visitor

How to fetch a specific string of data from a column using dax code?

I want to fetch the campaign string from the column Tags in my table if the value in the title column also contains campaign word and put it into another column. I want to search for the word "Campaign" in the tags column (so that in future if new campaign tags are added I won't have to update my code) and if it is present, I want to fetch just the campaign string present and no other tags. I can't use the split column using delimiter because not every row has this tag. 

 

eg:

 

Title                                                   Tags                                                          CampaignTagsWanted

Campaign Product A                      Campaign Jan, XYZ Tag                               Campaign Jan

Campaign Product B                      Campaign Feb, ABC Tag                              Campaign Feb

Campaign Product C                      Mar, LMN Tag                            

Product D                                       ABCD Tag, LMN Tag

 

SampleData.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: How to fetch a specific string of data from a column using dax code?

Hi @kavitaTickoo 

Could you accept to use Edit queries in Power BI?

I make a test as below

Please download my pbix file, open Edit queries,

click on the setp and the icon on right to see details for each step.

22.png

 

Steps:

In Edit queries,

1. Add column->add index column from 1

2. copy Table 1, paste to get Table 2

3. in Table2, click on column "Tags ", Transform->Split column->By delimiter "comma"

4. select "Tags .1" and "Tags .2", Transform->"Unpovit columns"

5. click on "Value" column, Transform->Format->trim

6. split column "Value" by delimeter 'space"

7. Add  column->conditional column21.png

8.  click on "Value.1" and "Value.2" columns, Add column->merge columns, thus get a column "Merged"

9.  filter rows: remove empty for "condition1",

10. select "Title", "Index","Merged", then Home->remove other columns

11. go to Table1, merge queries (Table1 and Table2) based on "index" column

Expand column "merged" from Table2

 

Best Regards
Maggie

 

Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

9 REPLIES 9
Gordonlilj Established Member
Established Member

Re: How to fetch a specific string of data from a column using dax code?

Hi,

 

Does this give you the result you are after?

CampaignTagsWanted = IF((SEARCH("Campaign", [Tags], 1, 0) > 0), LEFT([Tags],(FIND(",",[Tags],1,1)-1)))
kavitaTickoo Frequent Visitor
Frequent Visitor

Re: How to fetch a specific string of data from a column using dax code?

No, It is giving me blank rows.

Gordonlilj Established Member
Established Member

Re: How to fetch a specific string of data from a column using dax code?

Is it only returning blank rows?

And is it possible for you to post some more sample data

kavitaTickoo Frequent Visitor
Frequent Visitor

Re: How to fetch a specific string of data from a column using dax code?

I have attached a photo in the main query for reference.

Gordonlilj Established Member
Established Member

Re: How to fetch a specific string of data from a column using dax code?

Right,

One question

In the tags column are the campaign values always the first value in the string?

 

 

kavitaTickoo Frequent Visitor
Frequent Visitor

Re: How to fetch a specific string of data from a column using dax code?

No. The tags can be anywhere in the list.

Gordonlilj Established Member
Established Member

Re: How to fetch a specific string of data from a column using dax code?

Alright, that made it a bit worse

How about the delimiters, is there a max amount of delimiters or can there be an endless amount?

kavitaTickoo Frequent Visitor
Frequent Visitor

Re: How to fetch a specific string of data from a column using dax code?

There can be multiple tags. There is no specific count for the number of delimiters.

 

 

Community Support Team
Community Support Team

Re: How to fetch a specific string of data from a column using dax code?

Hi @kavitaTickoo 

Could you accept to use Edit queries in Power BI?

I make a test as below

Please download my pbix file, open Edit queries,

click on the setp and the icon on right to see details for each step.

22.png

 

Steps:

In Edit queries,

1. Add column->add index column from 1

2. copy Table 1, paste to get Table 2

3. in Table2, click on column "Tags ", Transform->Split column->By delimiter "comma"

4. select "Tags .1" and "Tags .2", Transform->"Unpovit columns"

5. click on "Value" column, Transform->Format->trim

6. split column "Value" by delimeter 'space"

7. Add  column->conditional column21.png

8.  click on "Value.1" and "Value.2" columns, Add column->merge columns, thus get a column "Merged"

9.  filter rows: remove empty for "condition1",

10. select "Title", "Index","Merged", then Home->remove other columns

11. go to Table1, merge queries (Table1 and Table2) based on "index" column

Expand column "merged" from Table2

 

Best Regards
Maggie

 

Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Summit North America

Power Platform Summit North America

Register by September 5 to save $200

PBI Community Highlights

PBI Community Highlights

Check out what's new in the Power BI Community!

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Top Kudoed Authors
Users Online
Currently online: 377 members 3,601 guests
Please welcome our newest community members: