cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Helper I

## Dynamic value replacement based on column type

Hello,

I have been stuck with this problem for several days. Here is the problem:

I have data columns with numbers except some are with "," and some with "."
I would like to dynamically convert the columns containing "." to ","

Here is an example :

 XXX Price YYY Price XXX Quantity YYY Quantity Product 11,55 12.40 13.50 12,50 AAAAA 18,90 15.90 74.60 65,15 BBBBBB 21,50 25.90 54.90 61,10 CCCCC

What I want is that all the columns that contain "Price" and "Quantity" are changed to type Number by replacing the "." by ","

Knowing that it must be dynamic because I have columns "ZZZ Price" and "ZZZ Quantity" that can appear.

I tried this solution:

= Table.TransformColumns(Source, List.Transform(List.Select(Table.ColumnNames(Source),each Text.Contains(_,"Price") or Text.Contains(_,"Quantity")), (col) => {col, each _ ?? null, type text}))

This code converts everything to text which allows me to change the "." to ","
But I have an error on the columns that don't contain "." because the type of these columns don't seem to be changed to text

Paul

1 ACCEPTED SOLUTION
Helper I

The problem comes from my formula that allows me to dynamically change the type of columns that contain the words "Price" and "Quantity".

So I used the following formula to change the type of the columns to text :

= Table.TransformColumnTypes(Source, List.Transform(List.Select(Table.ColumnNames(Source),each Text.Contains(_,"Price") or Text.Contains(_,"Quantity")), each {_, type text}))

This allowed me to use the following formula to replace the "." by "," without error :

= Table.ReplaceValue(PreviousStep,".",",",Replacer.ReplaceText,List.Select(Table.ColumnNames(PreviousStep),each Text.Contains(_,"Price") or Text.Contains(_,"Quantity")))

5 REPLIES 5
Helper I

The problem comes from my formula that allows me to dynamically change the type of columns that contain the words "Price" and "Quantity".

So I used the following formula to change the type of the columns to text :

= Table.TransformColumnTypes(Source, List.Transform(List.Select(Table.ColumnNames(Source),each Text.Contains(_,"Price") or Text.Contains(_,"Quantity")), each {_, type text}))

This allowed me to use the following formula to replace the "." by "," without error :

= Table.ReplaceValue(PreviousStep,".",",",Replacer.ReplaceText,List.Select(Table.ColumnNames(PreviousStep),each Text.Contains(_,"Price") or Text.Contains(_,"Quantity")))

Community Support

Hi @LeroyPaul ,

You want to replace the "." in multiple columns with ",", right?

If so, first make sure the columns contains "." are text type.

You can remove the "Change Types1" from Applied Steps to make them text.

Or select them and change types manually to make them text.

After the text type modification is complete, select columns at the same time, and then right-click a column to select the "Replace Values...".

Best Regards,

Stephen Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Helper I

Your solution allows me to do the operation in a static way but does not take into account the name of the columns so that it is dynamic.
As I will have new columns that will be added to my model later, these columns will not be modified using this solution.

Resident Rockstar

Hi @LeroyPaul  - you should consider using the Replace in Multiple Columns - Gorilla BI in two steps rather than Transform Columns in one step.  Use the Table.ColumnNames function to find Price and Quantity in these separate applied steps.

Helper I

I was able to develop my thoughts with the help of this website.

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

#### Power BI Monthly Update - August 2024

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

#### Fabric Community Update - August 2024

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

Top Solution Authors
Top Kudoed Authors