Forum Discussion
Add custom column in power query with IF-OR
- 5 years ago
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
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