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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
ggfd
New Member

Adding a new column from another with specific cell values

Hello group,

I have a spreadsheet column with incorrect values. However, there's no "one size fits all". In other words, I cannot apply a reduction of 25% to the entire column, as some cells are correct, others require a price reduction of 4%, others 7%, etc.

E.g.

ProductOld ValueFixed value
A1515
B108
C106.5

 

I wonder how the Fixed Value can be created by gathering info from Old Value. Perhaps a Python script can track the products names and correct the pricing?

@python 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @ggfd ,

You can achieve this in DAX easily if your data can be transformed into this:

vjunyantmsft_0-1707698127912.png

The data types of all columns except the first are Decimal number.
You can use these DAXs to create two new columns:

Fixed Expected Revenue 2023 = 'Table'[Expected Revenue 2023 (PowerBI column Type: decimal number)] * (1 - 'Table'[TASD1200])
Fixed Expected Revenue 2024 = 'Table'[Expected Revenue 2024 (PowerBI column Type: decimal number)] * (1 - 'Table'[TASD1200])

The final output is as below:

vjunyantmsft_1-1707698361296.png

 

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

View solution in original post

7 REPLIES 7
dufoq3
Super User
Super User

Ho, yes, its M. You can see my notes below how to use it.


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

ggfd
New Member

Hello dufoq3,
Thanks so much for your fast response. I aprreciate that.
However, is that M? I'm asking because the code works, but I would not know how to replicate or modify it in the future.
That's why I've been asking to get this help in Python, or even in DAX if python is too hard.
Thanks for the help again,

dufoq3
Super User
Super User

Hi @ggfd,

 

you can achieve expected result in Power Query

If you add more Expected Revenue Columns then Fixed Expected Revenue columns will be added automatically.

 

Result:

dufoq3_0-1707646344396.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tc9BC4JAEAXgvzII3URWY8lLh6B7QXUSDzaOZelszM4S/fuCzPb4YN7Hm6pK2EFH1J4bvEMnbgTiFjB4dSNJBtVxc9jmhTHrwi7qJE1Ohy18YmbMFPLUfGOdVklgHxDJ+y4MoOS150tkLIvZsLFR2FnYi7sRKmDDSMNAbbwhN2YGyhhY/oHd4+FEA/f6AhRqlFroGfRK8BT3mYNBhBhfMHVXNl7y/+XpOAXtRwJ1MDZyJ/0dlXlmy9//U6N+Aw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Close Reason" = _t, #"Expected Revenue 2023" = _t, #"Expected Revenue 2024" = _t]),
    ChangedTypeRevenueDynamic = Table.TransformColumns(Source, List.Transform(List.Select(Table.ColumnNames(Source), each Text.Contains(_, "Revenue", Comparer.OrdinalIgnoreCase)),
      (colName)=> { colName, each Currency.From(Text.AfterDelimiter(_, " "), "en-US"), Currency.Type } )
  ),
    Ad_Percentage = Table.AddColumn(ChangedTypeRevenueDynamic, "Percentage", each Percentage.From(Text.BetweenDelimiters([Close Reason], "=", "]")), Percentage.Type),
    AddedFixedColumnsDynamic = List.Accumulate( 
    List.Select(Table.ColumnNames(Source), each Text.Contains(_, "Revenue", Comparer.OrdinalIgnoreCase)),
    Ad_Percentage,
    (s,c)=> Table.AddColumn(s, "Fixed " & c, each Record.Field(_, c) * (1 - [Percentage]), Currency.Type)
)
in
    AddedFixedColumnsDynamic

 


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

ggfd
New Member

 

 

2 seconds ago

Hello,
I'm sorry for the delay. I'm new on PowerBI so I was reviewing the problem to better describe what I'm trying to do.

Part of my dataset is below. The columns in red don't exist, so they are what I've been trying to create using python:

Close Reason (PowerBI column type: text)Expected Revenue 2023 (PowerBI column Type: decimal number)Fixed Expected Revenue 2023 (PowerBI column Type: decimal number)
Expected Revenue 2024 (PowerBI column Type: decimal number)Fixed Expected Revenue 2024 (PowerBI column Type: decimal number)
no feedback from end customer. [TASD1200=25%]USD 200.00 USD 1,000.00 
unsuccessful testing [TASD1200=32%]USD 500.00 USD 250.00 
Project cancelled. [TASD1200=100%]USD 800.00 USD 350.00 
Opportunity created in the wrong currency USD 750.00 USD 200.00 
won, time to marketUSD 281.58 USD 100.00 

 

The new columns, "Fixed Expected Revenue 2023" and "Fixed Expected Revenue 2024," should be filled with the values obtained by subtracting the discount percentage specified in "Close Reason" column TASD1200 percentage from the "Expected Revenue 2023" and "Expected Revenue 2024" respectively.

Example:

Close Reason (PowerBI column type: text)Expected Revenue 2023 (PowerBI column Type: decimal number)Fixed Expected Revenue 2023 (PowerBI column Type: decimal number)
Expected Revenue 2024 (PowerBI column Type: decimal number)Fixed Expected Revenue 2024 (PowerBI column Type: decimal number)
no feedback from end customer. [TASD1200=25%]USD 200.00200 - (200*25%) = 150USD 1,000.001000 - (1000*25%) = 750

 

Is it possible to create that using python?

E.g.

Transform data > Run Python script?

 

I prefer to use Python rather than DAX. However, if Python is too complicated, a DAX script is fine.

 

Thanks a lot for the help,

 

Anonymous
Not applicable

Hi @ggfd ,

You can achieve this in DAX easily if your data can be transformed into this:

vjunyantmsft_0-1707698127912.png

The data types of all columns except the first are Decimal number.
You can use these DAXs to create two new columns:

Fixed Expected Revenue 2023 = 'Table'[Expected Revenue 2023 (PowerBI column Type: decimal number)] * (1 - 'Table'[TASD1200])
Fixed Expected Revenue 2024 = 'Table'[Expected Revenue 2024 (PowerBI column Type: decimal number)] * (1 - 'Table'[TASD1200])

The final output is as below:

vjunyantmsft_1-1707698361296.png

 

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

Anonymous
Not applicable

Hi @ggfd ,

Please try this:
Here is my sample data:

vjunyantmsft_0-1706845841716.png

 

Use this DAX to create a new column:

 

Fixed Value = 
SWITCH(
    TRUE(),
    'Table'[Product] = "B", 'Table'[Old Value] * 0.8,
    'Table'[Product] = "C" || 'Table'[Product] = "D", 'Table'[Old Value] * 0.65,
    'Table'[Old Value]
)

 

The final output is below:

vjunyantmsft_2-1706845621740.png

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

speedramps
Super User
Super User

We want to help you but your description is too vaugue. Please write it again clearly.

Provide example input data.

Also provide the example desired output, with a clear step-by-step description of any calcutations the process flow.

Try keep it simple and ask one question per ticket.
You will get a quick response if you put time, care and effort into writing clear problem descriptions.
Remember you are gerrting free expert help, so please put lots of proper effort to asking questions and providing example.

Vaugue descriptions can waste your time and ourtime.

Look foward to helping you when the above information is forthcoming

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.