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
mindfulmike
Frequent Visitor

How to find a single cell in a column with an if then divide it by 5 without making a new column

Hi all, 

 

I have 2 columns, Clients and their Totals. One client needs to have their total divided by 5. 

 

I made a conditonal column that works, formula: = Table.AddColumn(#"Added Custom", "Custom", each if [Client] = "ABC" then [Total]/5 else [Total])

 

Althouugh this works, is there a way to select the Total column and do this without creating a new column?

 

As far as I know the this cannot be done under Transform, Standard operations because I cannot us an each if expression. 

 

Thanks!

 

1 ACCEPTED SOLUTION
v-cgao-msft
Community Support
Community Support

Hi @mindfulmike ,

 

Please try:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTI0VIrVATKdgGwjIyjbGcgxNlaKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Clients = _t, Totals = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Clients", type text}, {"Totals", Int64.Type}}),
    Custom1 = Table.FromColumns({Table.ToColumns(#"Changed Type"){0}} & {List.Transform(Table.ToRows(#"Changed Type"), each if _{0}="ABC" then _{1}/5 else _{1})},{"Clients","Totals"})
in
    Custom1

vcgaomsft_0-1675825977520.png

vcgaomsft_1-1675825990124.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

3 REPLIES 3
wdx223_Daniel
Super User
Super User

=Table.ReplaceValue(PreviousStepName,each [Client],5,(x,y,z)=>if y="ABC" then x/z else x,{"Total"})

v-cgao-msft
Community Support
Community Support

Hi @mindfulmike ,

 

Please try:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTI0VIrVATKdgGwjIyjbGcgxNlaKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Clients = _t, Totals = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Clients", type text}, {"Totals", Int64.Type}}),
    Custom1 = Table.FromColumns({Table.ToColumns(#"Changed Type"){0}} & {List.Transform(Table.ToRows(#"Changed Type"), each if _{0}="ABC" then _{1}/5 else _{1})},{"Clients","Totals"})
in
    Custom1

vcgaomsft_0-1675825977520.png

vcgaomsft_1-1675825990124.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

smpa01
Super User
Super User

@mindfulmike 

Table.SelectRows(prevStep, each ([Column1]/5 = 1))
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

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.

Top Solution Authors
Top Kudoed Authors