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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Mendes094
New Member

Change a cell without create a new colunm

Hello, 

I have a table and I need change the value for 0 when Type is B. How can I do this without create a new colunm in Power query?

 

TypeValueResults
A1010
B200
C4040
D5050

 

Tks!

1 ACCEPTED SOLUTION
rohit1991
Super User
Super User

Hi @Mendes094 ,

To update Value directly without a new column:

let
    Source = YourTable,
    UpdatedTable = Table.TransformColumns(Source, {{"Value", each if [Type] = "B" then 0 else _, type number}})
in
    UpdatedTable

This modifies Value based on Type without adding a new column.


Did it work? ✔ Give a Kudo • Mark as Solution – help others too!

View solution in original post

9 REPLIES 9
v-nmadadi-msft
Community Support
Community Support

Hi @Mendes094 ,

As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided by the community members for the issue worked. If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.

 

Thanks ands regards

v-nmadadi-msft
Community Support
Community Support

Hi @Mendes094 ,

I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If the responses has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.

Thank you

v-nmadadi-msft
Community Support
Community Support

Hi @Mendes094 ,

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

Thanks and Regards

rohit1991
Super User
Super User

Hi @Mendes094 ,

To update Value directly without a new column:

let
    Source = YourTable,
    UpdatedTable = Table.TransformColumns(Source, {{"Value", each if [Type] = "B" then 0 else _, type number}})
in
    UpdatedTable

This modifies Value based on Type without adding a new column.


Did it work? ✔ Give a Kudo • Mark as Solution – help others too!

Hi @rohit1991, this won't work in my opinion. You can't refer another column in Table.TransformColumns. That is the reason why I showed solution with Table.TransformRows.


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Hi @dufoq3,


TransformColumns cannot reference another column. Here's an alternative approach using Table.TransformRows to update the Value column without creating a new one:

let
Source = YourTable,
UpdatedTable = Table.FromRecords(
Table.TransformRows(Source, each Record.TransformFields(_, {{"Value", if _[Type] = "B" then 0 else _[Value]}}))
)
in
UpdatedTable

This method ensures the Value column is updated based on the Type without creating a new column. Let me know if you have further questions or need more clarification!



Did it work? ✔ Give a Kudo • Mark as Solution – help others too!
dufoq3
Super User
Super User

Hi @Mendes094, another solution:

 

Output

dufoq3_0-1737821809655.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTI0UIrViVZyAjKNIExnINMEwnQBMk2BzFgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Type = _t, Value = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Value", type number}}),
    ReplacedValue = Table.FromRecords(Table.TransformRows(ChangedType, each _ & (if [Type] = "B" then [Value = 0] else [])), Value.Type(Table.FirstN(ChangedType, 0)))
in
    ReplacedValue

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

v-nmadadi-msft
Community Support
Community Support

Hi @Mendes094  ,
Thanks for reaching out to the Microsoft fabric community forum.
I would like to thank @m_dekorte  for their suggestion
I have tried to reproduce their M query.
I have imported data from Excel and then used their suggested M query to get required output

vnmadadimsft_0-1737720016820.png

let
    Source = Excel.Workbook(File.Contents("C:\Users\Downloads\elif_.xlsx"), null, true),
    Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Type", type text}, {"Value", Int64.Type}, {"Results", Int64.Type}}),
    #"ReplaceValue" = Table.ReplaceValue(#"Changed Type",each [Value],each if [Type]="B" then 0 else [Value],Replacer.ReplaceValue,{"Value"})
in
    #"ReplaceValue"

It has successfully got the desired output 


Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to give "Kudos"
Thanks and Regards

m_dekorte
Super User
Super User

Hi @Mendes094,

 

There are several options available, but using "Replace Values" is likely the most intuitive choice.

let
    Source = Table.FromRecords(
        {
            [Type = "A", Value = 10],
            [Type = "B", Value = 20],
            [Type = "C", Value = 40],
            [Type = "D", Value = 50]
        },  type table [Type=text, Value=number]
    ),
    ReplaceValue = Table.ReplaceValue(Source,each [Value],each if [Type]="B" then 0 else [Value],Replacer.ReplaceValue,{"Value"})
in
    ReplaceValue

 

I hope this is helpful

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors
Top Kudoed Authors