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

Creating multiple columns. Use result of Table.SplitColumn to determine cell value

Hi,

I have this code:

#"Split Column by Delimiter3" = Table.SplitColumn(#"Reordered Columns" , "Custom2", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), ListB),

Leroy_3-1644549307312.png

Which creates multiple columns from this list with data from the Custom2 column.

Leroy_1-1644548712143.png 

 

and this is the result

Leroy_0-1644548607889.png

Now I want to add if the result in each cell is blank or null then  0 (zero) else $200.

so the result word look like

Leroy_2-1644549265119.png

 

Given that the code creates multiple columns at once what code to i need to wrap around or put inside the existing code for #"Split Column by Delimiter3"?

 

Any help would be appreciated.

Thanks

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi All,

I worked it out! Thanks to Gorilla BI and his YouTube Video "Check if Column Contains Item from List in Power Query - Create Text.ContainsAny!" pointed me in the right direction by using

 

Table.AddColumn(#"Duplicated Column4", "Custom2", each List.Transform(Text.Split([Custom2prep],","),each "$200")).

 

The important bits are Custom2 is the column to be split by comma and the items to then be replaced with "$200"

Then the Table.SplitColumn(#"Extracted Values1" , "Custom2", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), ListB)

 

This made the whole bit dynamic so it doesn't matter if the data need 2 columns or 70 columns saving manual creation of columns

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

I've tried to test using List.ReplaceValue(Text.Split([Custom2],","),"0","$200", Replacer.ReplaceText) which almost works by replacing the "0" in eg "S904/01" with "$200" so it reads "S9$2004/01". How would I turn this into For any value replace the whole value with $200

Anonymous
Not applicable

Hi Allison,

 

Thanks for your input. 

 

The Custom2 column may have 50+ 'values'./ There are 70+ rows with each row having between 1 & 50+ values.

The prior step using the Table.SplitColumn method splits into the 50+ columns automatically.

 

What I am after is a 'non manual' way of making the result in the cell a predetermined value, say $200, if the prior step for that cell has a 'value' (eg S9962/01) or null/blank/zero if the prior step is a 'blank cell'.

 

I can do it manually like you suggested but the data varies each time and it would be more efficient to find a 'automated ' way of doing it.

 

Thanks

AllisonKennedy
Super User
Super User

@Anonymous  What is your final goal? I would guess that you might benefit from an 'unpivot columns' here:

If you need 0 instead of null: - Select all your new columns > Transform > Replace Values > null to 0

Then: - Select your new columns > Transform > unpivot selected columns

Finally: - Select the Add Column > Conditional Column > If [Value] = 0, then 0 otherwise 200

That should get you the ideal data for loading into Power BI. You can do the pivoting in the visuals within the report.


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Anonymous
Not applicable

Hi All,

I worked it out! Thanks to Gorilla BI and his YouTube Video "Check if Column Contains Item from List in Power Query - Create Text.ContainsAny!" pointed me in the right direction by using

 

Table.AddColumn(#"Duplicated Column4", "Custom2", each List.Transform(Text.Split([Custom2prep],","),each "$200")).

 

The important bits are Custom2 is the column to be split by comma and the items to then be replaced with "$200"

Then the Table.SplitColumn(#"Extracted Values1" , "Custom2", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), ListB)

 

This made the whole bit dynamic so it doesn't matter if the data need 2 columns or 70 columns saving manual creation of columns

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.