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
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
Anonymous
Not applicable

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
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.