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
AlyssaP17
Helper I
Helper I

Custom Column else if divide

Current column is [Days to Close] new custom column is Avg. Days Worked 

 

I would the like formula to say if [days to close] is greater than or equal to 181 then 90 and if [days to close] is less than or equal to 180 then divide the days to close by 2. 

the first part of my formula works but the second part isn't and I have spent too many hours trying to rework the formula. 

=if [Days to Close]>=181 then 90 else if [Days to Close]<=180 then Value.Divide ([Days to Close], 2)

1 ACCEPTED SOLUTION

@AlyssaP17 

Create a new column using the following DAX

custom column = IF('Table'[Days] > 501, [Days]/4,IF( [Days]<=500 && 'Table'[Days] >= 180, [Days]/3, IF([Days]<180, [Days]/2)))
if.PNG
 

 

View solution in original post

6 REPLIES 6
lit2018pbi
Resolver II
Resolver II

@AlyssaP17 

create a new column  as 

Column 2 = IF('Table'[Days] >= 181, 90, IF('Table'[Days] <= 180, 'Table'[Days]/2))
 
if.PNG

 

harshnathani
Community Champion
Community Champion

Hi @AlyssaP17 ,

 

 

In M Code

Custom Column=if [Days to Close]>=181 then 90 else if [Days to Close]<=180 then [Days to Close]/ 2

 

 

In DAX (Calculated Column)

 

Column =
SWITCH(
TRUE(),
Table[Days to Close] >= 181 , 90,
DIVIDE(Table[Days to CLose],2)

 

Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

@harshnathani Thank you, I am using M code. My formula changed and this is what I have entered. I am still getting the "Token Else expected" error. 

custom column=if[Days to Close]>501 then [Days to Close]/4 else if [Days to Close]<=500 then [Days to Close]/3 else if [Days to Close]<180 then [Days to Close]/2

 

Do you think this would be easier in DAX? 

Hi @AlyssaP17 .

 

Use this for M Code.

 

if [Days to Close]<180 then [Days to Close]/2 else if  [Days to Close]<=500 then [Days to Close]/3 else [Days to Close]/4

 

Additionally, you can use add contional columns

 

1.jpg

 

 

To nest an if within another if we use the same if – then – else methodology, as shown below

= if [thing to to test #1]  = "something else" then [do this if true]
else if [thing to to test #2]  = "something else" then [do this if true] else 
[do this if false]

 

https://exceloffthegrid.com/power-query-if-statements-for-conditional-logic/

 

Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

 

 

 

@AlyssaP17 

Create a new column using the following DAX

custom column = IF('Table'[Days] > 501, [Days]/4,IF( [Days]<=500 && 'Table'[Days] >= 180, [Days]/3, IF([Days]<180, [Days]/2)))
if.PNG
 

 

Anonymous
Not applicable

let's consider your column name is days_close.

 

You can try this DAX in your calculated columns using Divide function,

 

=if([days_close]>=181, 90, if([days_close]<=180, Divide([days_close],2),0))

 

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.