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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Maahmohammed
Helper I
Helper I

How to use if function in the mathematical calculations?

I have 2 columns, one is the product_id & the other is the GM%,

I need to create the below calculated column or a measure with the below formaula:

If(GM%<10,"0",
IF(GM%<20,"Divide(GM%,2)",
"10"
))

But the output of (if) is text, i couldn't make a calculation.

How could you help me?

Regards

Maahmohammed_0-1726768093916.png

 

1 ACCEPTED SOLUTION
dharmendars007
Super User
Super User

Hello @Maahmohammed , 

 

Please try the below measure I have used Switch instead of "IF" which is more readable.

 

AdjustedGMMeasure =
SWITCH(TRUE(),
SUM(Table[GM]) < 10, 0,
SUM(Table[GM]) < 20, DIVIDE(SUM(Table[GM]), 2),10)

 

If you find this helpful , please mark it as solution which will be helpful for others and Your Kudos/Likes are much appreciated!

 

Thank You

Dharmendar S

LinkedIN 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @Maahmohammed 

 

Make sure that the data format of the "GM%" column is a numeric type.

vxianjtanmsft_1-1726814572497.png

In my simple test, the measure works.

Also, the SWITCH function suggested in dharmendars007's reply is a valid solution.

 

AdjustedGM% = IF(SELECTEDVALUE('Table'[GM%]) < 10, 0, IF(SELECTEDVALUE('Table'[GM%]) < 20, DIVIDE(SELECTEDVALUE('Table'[GM%]), 2), 10))

 

vxianjtanmsft_0-1726814262204.png

 

Best Regards,
Jarvis Tang
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 @Maahmohammed 

 

Just a friendly follow up on the case, may I know if these replies have helped you resolve the issue? If they have, please consider accepting helpful reply as a solution.

 

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

dharmendars007
Super User
Super User

Hello @Maahmohammed , 

 

Please try the below measure I have used Switch instead of "IF" which is more readable.

 

AdjustedGMMeasure =
SWITCH(TRUE(),
SUM(Table[GM]) < 10, 0,
SUM(Table[GM]) < 20, DIVIDE(SUM(Table[GM]), 2),10)

 

If you find this helpful , please mark it as solution which will be helpful for others and Your Kudos/Likes are much appreciated!

 

Thank You

Dharmendar S

LinkedIN 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.