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

Subtraction only if result is not X

Hi all,

 

I had a question I want to subtract a fixed value from a column BUT only when the result is => 5, so for example:

If my fixed value is 5 I want the result to look like this: (I want this result as a calculated column)

2015
3025
2520
00
5045
55

 

Thanks in advance !

 

Best Regards,

L.Meijdam

1 ACCEPTED SOLUTION
jthomson
Solution Sage
Solution Sage

newcolumnname=if([existingcolumnname]<5,[existingcolumnname],[existingcolumnname]-5) should work

View solution in original post

7 REPLIES 7
WolfBiber
Employee
Employee

Try following code, you need to change Source here of course, FixedParam is a Parameter of type Number

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjJQ0lEyNFWK1YlWMgaxjSBsIKUDkgSxQcIQlimIaQJRAVIAZMUCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Column1] > FixedParam then [Column1]-5 else [Column1])
in
    #"Added Custom"

 

jthomson
Solution Sage
Solution Sage

newcolumnname=if([existingcolumnname]<5,[existingcolumnname],[existingcolumnname]-5) should work

Anonymous
Not applicable

Hi @jthomson,

 

I get the error message stating "The end of input was reached."

 

Hi@WolfBiber,

 

If possible I am looking for a solution in DAX

 

Best regards,

L.Meijdam

 

then use formula from @jthomson and replace , with ; 

newcolumnname=if([existingcolumnname]<5;[existingcolumnname];[existingcolumnname]-5)
Anonymous
Not applicable

Hi @WolfBiber,

 

I already do that by default so it is not making a difference.

 

Best regards,

L.Meijdam

@Anonymous

 

The formula provided by @WolfBiber and @jthomson should work. You need to add this calculated column outside of Query Editor. 

 

24.PNG

 

Regards,

Anonymous
Not applicable

Hi @v-sihou-msft@WolfBiber@jthomson

 

I am not sure what I did but the code is returning no errors anymore .. I made no changes.

 

But anyway thanks for the help the code provided works like expected now !

 

Best Regards,

L.Meijdam

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.