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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
vkomarag
Helper III
Helper III

Replace the text values and some number values in a number field and do the same for a range of cols

Hi,

 

I have 300 fields in an excel. 260 columns has some ratings(1,2,3,4,5 as values). Unexpectedly there are values other than (1,2,3,4,5) and some text values in the fields. I need to replace the values other than 1,2,3,4,5 to blank value.

 

I need to do this for a range of 260 columns which are in sequential order.

 

Any pointers on this except R programming solution?

 

Thanks

Venkata

1 ACCEPTED SOLUTION
ImkeF
Community Champion
Community Champion

If the 1-5-values you want to keep are real numbers, then this code will work (assuming you've kept the default-naming from the unpivot-operation "Value"):

 

let
    Source = YourTable,
    Keep = #table({"Keep"}, {{1},{2},{3},{4},{5}}),
    #"Merged Queries" = Table.NestedJoin(Source,{"Value"},Keep,{"Keep"},"NewColumn",JoinKind.LeftOuter),
    #"Expanded NewColumn" = Table.ExpandTableColumn(#"Merged Queries", "NewColumn", {"Keep"}, {"Keep"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded NewColumn",{"Value"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Keep", "Value"}})
in
    #"Renamed Columns"

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Does it need to be done in Power BI?  What is your data source?  Can you clean it up there?  If it was excel, i'd suggest a clean up macro.

ImkeF
Community Champion
Community Champion

This can easily be done in the query editor using this code:

 

let
    Source = YourTable,
    ChangeAllColumnsToText = Table.TransformColumnTypes(Source, List.Transform(Table.ColumnNames(Source), each {_, type text})),
    KeepOnlyOneToFives = Table.TransformColumns(ChangeAllColumnsToText,{}, (x) => Text.Combine(List.Select(Text.ToList(x), each List.Contains({"1", "2", "3", "4", "5"}, _)), ""))
in
    KeepOnlyOneToFives

 Just replace "YourTable" in the 1st Source-step by a reference to your table/query.

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Thanks for your input. I got a way in case if i do anything in the future. For now, I am getting conversion error. I have unpivoted the column and converted into just one column called Rating.I have values(1,2,3,4,5,96,Yes,No)..Now i need to repalce all the values other than 1,2,3,4,5 to blank. Appreciate your response.

ImkeF
Community Champion
Community Champion

If the 1-5-values you want to keep are real numbers, then this code will work (assuming you've kept the default-naming from the unpivot-operation "Value"):

 

let
    Source = YourTable,
    Keep = #table({"Keep"}, {{1},{2},{3},{4},{5}}),
    #"Merged Queries" = Table.NestedJoin(Source,{"Value"},Keep,{"Keep"},"NewColumn",JoinKind.LeftOuter),
    #"Expanded NewColumn" = Table.ExpandTableColumn(#"Merged Queries", "NewColumn", {"Keep"}, {"Keep"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded NewColumn",{"Value"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Keep", "Value"}})
in
    #"Renamed Columns"

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Yeah got it. I have changed the Source to my previous column in the Merged Queries step and it worked out. Thanks a lot.

 

You are genius !  We are suggesting this tool for our business to do their own development activities. I am just wondering how could they code this kind of things all the times.

 

Anyway. Your excellence helped a lot.

After unpivoting, i didnt change the column name. by default it is " Value". After using your code,an error occured saying that 

" The column 'Value' of the table was not found"

and the Merged queries step got highlighted.

Helpful resources

Announcements
October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors