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

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

Reply
anandmitta
Helper I
Helper I

Custom column based on 2 different columns

Hello community, please excuse me if this scenario has already been answered.

 

I have a table with 4 columns.

IDBookNoCont NoCreated date
12341111122222-Feb-22
23452222 26-Mar-22
3456333334443-Apr-22
4567  12-Mar-22
5678  25-Mar-22
6789 76662-Feb-22
78904444564531-Jan-22

 

Above is the sample data.

 

I want a custom column with values 0, 1, 2 with the respective below conditions.

1) If the date difference is less than 7 days between created date and current date then the custom column should be '0'.

2) If the date difference is 7-12 days between created date and current date, and either of BookNo or ContNo is empty then custom column value should be '1'. If BookNo and ContNo is not empty then '0'.

3) If the date difference is greater than 12 days between created date and current date, and either of BookNo or ContNo is empty then custom column value should be '2'. If BookNo and ContNo is not empty then '0'.

 

Below is the expected result

Current date: 4-Apr-22

IDBookNoCont NoCreated dateCustom Column
12341111122222-Feb-220
23452222 26-Mar-221
3456333334443-Apr-220
4567  12-Mar-222
5678  25-Mar-221
6789 76662-Feb-222
78904444564531-Jan-220

 

I have been trying to do this and I'm getting error when trying to create a custom column based on 2 column values. 

 

Please help me with this.

 

Thanks & Regards,

Anand

 

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@anandmitta , Create a new column like

New column =

var _diff = datediff([created_date], today(), day)+1

return

Switch(true() ,

_diff <7, 0 ,

_diff <= 12 && isblank([Book No]) && isblank([Cont No])   , 0,

_diff <= 12   , 1,

_diff > 12 && isblank([Book No]) && isblank([Cont No])   , 0,

_diff <= 12   , 2,

0)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

Thank you so much @amitchandak. It worked 

 

There was just 1 small correction to the above query. The value should be 1 or 2 if it falls in the specific date range and book no and cont no are empty. where as the above query makes it 0. Below is the corrected query.

 

New column =

var _diff = datediff([created_date], today(), day)+1

return

Switch(true() ,

_diff <7, 0 ,

_diff <= 12 && isblank([Book No]) && isblank([Cont No])   , 1,

_diff <= 12   , 0,

_diff > 12 && isblank([Book No]) && isblank([Cont No])   , 2,

_diff <= 12   , 0,

0)

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@anandmitta , Create a new column like

New column =

var _diff = datediff([created_date], today(), day)+1

return

Switch(true() ,

_diff <7, 0 ,

_diff <= 12 && isblank([Book No]) && isblank([Cont No])   , 0,

_diff <= 12   , 1,

_diff > 12 && isblank([Book No]) && isblank([Cont No])   , 0,

_diff <= 12   , 2,

0)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thank you so much @amitchandak. It worked 

 

There was just 1 small correction to the above query. The value should be 1 or 2 if it falls in the specific date range and book no and cont no are empty. where as the above query makes it 0. Below is the corrected query.

 

New column =

var _diff = datediff([created_date], today(), day)+1

return

Switch(true() ,

_diff <7, 0 ,

_diff <= 12 && isblank([Book No]) && isblank([Cont No])   , 1,

_diff <= 12   , 0,

_diff > 12 && isblank([Book No]) && isblank([Cont No])   , 2,

_diff <= 12   , 0,

0)

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.

Top Solution Authors