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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
medwards
Frequent Visitor

Nested if statement based on dates for New Column

Hope you can kindly assist. I'm trying to write a nested if statement for a new column I created, but I'm having trouble with the syntax. My new column is called "WEEK #" where it is the number of weeks after the start date (Jan 30, 2023).

 

WEEK # = IF(
'TABLE'[Completed Date] >= DATE(2023,1,30) AND <= DATE(2023,2,4),1,
(IF('TABLE'[Completed Date] >= DATE(2023,2,5) AND <= DATE(2023,2,11),2,
(IF('TABLE'[Completed Date] >= DATE(2023,2,12) AND <= DATE(2023,2,18)),3,
(IF('TABLE'[Completed Date] >= DATE(2023,2,19) AND <= DATE(2023,2,25)),4,
(IF('TABLE'[Completed Date] >= DATE(2023,2,26) AND <= DATE(2023,3,4)),5),
ELSE " ")))))
 
If there's an easier way to do this, I'm open to other ideas. Thanks!
1 ACCEPTED SOLUTION
Syk
Resident Rockstar
Resident Rockstar

Try using the datediff function instead... Something similar to this:

Weeks_After_Start_Date = DATEDIFF("1/30/2023", 'Table'[Completed Date], WEEK)

View solution in original post

2 REPLIES 2
medwards
Frequent Visitor

Thank you! That is so much easier 🙂

Syk
Resident Rockstar
Resident Rockstar

Try using the datediff function instead... Something similar to this:

Weeks_After_Start_Date = DATEDIFF("1/30/2023", 'Table'[Completed Date], WEEK)

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.