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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Calculated Column with multiple conditions

i have a table with following columns.

 

                                                                                             Leave Details

 

EmployeeName      Leave taken days     Leave Type           Start Date         End Date      Month diff      Created colum

 

   A                               5                        Work from home      24/12/2018        29/12/2018          1                 0

   B                              120                     Vacation Leave          01/06/2018        31/122018           6                 0

   C                              10                       Marraige leave          01/06/2018       10/06/2018          1                 5

 

work from home should not consider as a leave, return created column as 0

marraige leave should not consider as a leave if leave taken days <5, want remaining days if leave taken days >5 in a created column.

vacation leave should not consider as a leave if month diffe <=6, return created column as 0.

 

i tried the following dax  query:

 

Created Column =
SWITCH(TRUE(),
'Leave Details'[Request type] = "Work From Home" && 'Leave Details'[Leave taken days] >0,0,
'Leave Details'[Request type] = "Vacation Leave" && 'Leave Details'[Month diff]=6,'Leave Details'[Month diff]= -6,
'Leave Details'[Request type] = "Marriage" && 'Leave Details'[Leave taken days]>=5,'Leave Details'[Leave taken days] - 5,
'Leave Details'[Request type] = "Vacation Leave" && 'Leave Details'[Month diff]<6,0,
'Leave Details'[Request type] = "Marriage" && 'Leave Details'[Leave taken days]<5,0,
'Leave Details'[Leave taken days]
)

 

error Occurs :  Expressions that yield variant data-type cannot be used to define calculated columns.

 

 

 

 

 

 

1 ACCEPTED SOLUTION
v-chuncz-msft
Community Support
Community Support

@Anonymous,

 

You may remove the equal sign (=) in expression below.

'Leave Details'[Month diff]= -6,
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-chuncz-msft
Community Support
Community Support

@Anonymous,

 

You may remove the equal sign (=) in expression below.

'Leave Details'[Month diff]= -6,
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
ryan_mayu
Super User
Super User

@Anonymous

 

please try if formula instead of switch. It should fit your requirement. Thanks

Column = 
    if(Sheet2[leavetype]="a"&&Sheet2[leave taken days]>0,0,
        if(Sheet2[leavetype]="b"&&'Sheet2'[month diff]=6,Sheet2[month diff]-6
            ,if(Sheet2[leavetype]="c"&&Sheet2[leave taken days]>=5,Sheet2[month diff]-5,111)))

screenshot.JPG





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

Proud to be a Super User!




Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.