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
wlljhn
Regular Visitor

Add custom column in power query with IF-OR

Hi

I'm trying to add new column in power query with condition that I will normally use in excel as follow:

if(or(weekday([Date],2)=5,weekday([Date],2)=6),weeknum([Date]+3,2),weeknum([Date]+2,2)

 

Really appreciate any help on how to do it in power query.

 

regards

1 ACCEPTED SOLUTION
edhans
Super User
Super User

It is very similar, just a slightly different syntax:

if(or(weekday([Date],2)=5,weekday([Date],2)=6),weeknum([Date]+3,2),weeknum([Date]+2,2)

Becomes

if Date.DayOfWeek([Date],Day.Monday) = 5 or Date.DayOfWeek([Date],Day.Monday) = 6
then Date.WeekOfYear(Date.AddDays([Date],3),Day.Monday)
else Date.WeekOfYear(Date.AddDays([Date],2),Day.Monday)

Without actual data hard to verify so check it out. the Day.Monday parameter just says what the first day of the week is, so change that as desired. I think the ,2, in Excel does the same.

 

In Power Query, there is no IF() function, but you use if/then/else, and else is always required. If you don't need it just use else null to return nothing. if/then/else is always 100% lowercase too.

 

I put line breaks in my formula above. You don't have to, but easier to read I think. See if that helps @wlljhn 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

2 REPLIES 2
CNENFRNL
Community Champion
Community Champion

Hi, @wlljhn , given that return values of excel WEEKDAY(param1, return_type) function vary based on return_type as such,

Return_type         Number returned

1 or omitted

Numbers 1 (Sunday) through 7 (Saturday).

2

Numbers 1 (Monday) through 7 (Sunday).

3

Numbers 0 (Monday) through 6 (Sunday).

 

I'd like to verify that you exam the [Date] is either Friday or Saturday, don't you? If so, its equivalent in Power Query is like this

 

if Date.DayOfWeek([Date],Day.Sunday) >= 5 
then Date.WeekOfYear(Date.AddDays([Date],3),Day.Monday)
else Date.WeekOfYear(Date.AddDays([Date],2),Day.Monday)

 

 


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

edhans
Super User
Super User

It is very similar, just a slightly different syntax:

if(or(weekday([Date],2)=5,weekday([Date],2)=6),weeknum([Date]+3,2),weeknum([Date]+2,2)

Becomes

if Date.DayOfWeek([Date],Day.Monday) = 5 or Date.DayOfWeek([Date],Day.Monday) = 6
then Date.WeekOfYear(Date.AddDays([Date],3),Day.Monday)
else Date.WeekOfYear(Date.AddDays([Date],2),Day.Monday)

Without actual data hard to verify so check it out. the Day.Monday parameter just says what the first day of the week is, so change that as desired. I think the ,2, in Excel does the same.

 

In Power Query, there is no IF() function, but you use if/then/else, and else is always required. If you don't need it just use else null to return nothing. if/then/else is always 100% lowercase too.

 

I put line breaks in my formula above. You don't have to, but easier to read I think. See if that helps @wlljhn 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

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.