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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Transform a column with an 'If statement'

Hi,

 

I would like to modify a column without creating a new one. Basically I want to apply a rule:

 

If value >= 5, then 5.

 

Is there an easy way to do it without creating a new calculated field or measure?


Thanks

 

Jon

1 ACCEPTED SOLUTION
harshnathani
Community Champion
Community Champion

Hi @Anonymous ,

 

You will need to create this as a new column or a new measure.

 

Else filter this condition of value >= 5 at the source itself.

 


Regards,

Harsh Nathani


Appreciate with a Kudos!! (Click the Thumbs Up Button)

Did I answer your question? Mark my post as a solution!

 

View solution in original post

3 REPLIES 3
sreenathv
Solution Sage
Solution Sage

You can do that in power query. While importing the data, select "Add conditional column" option.

 

Add Conditional Column.png

The result will be as follows...

Add Conditional Column1.png

Then remove the field "Value" (Right-click, Remove) before applying the changes. Internally the power query generated automaticall will look like this.

 

let
    Source = Excel.Workbook(File.Contents("C:\Users\S\Documents\Book1.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",{{"Item", type text}, {"Value", Int64.Type}}),
    #"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Custom", each if [Value] >= 5 then 5 else [Value]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column",{"Value"})
in
    #"Removed Columns"

 

amitchandak
Super User
Super User

@Anonymous , May be power query you can edit the source script and try. Best is you create a new column only

 

if([value]>5,5,blank())

harshnathani
Community Champion
Community Champion

Hi @Anonymous ,

 

You will need to create this as a new column or a new measure.

 

Else filter this condition of value >= 5 at the source itself.

 


Regards,

Harsh Nathani


Appreciate with a Kudos!! (Click the Thumbs Up Button)

Did I answer your question? Mark my post as a solution!

 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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