STARTOFWEEK, END OF WEEK error

Hi I have used the AI tool to help me create the following function, however the intellisense does not recognise the STARTOF WEEK or ENDOFWEEK function

Please see code below;

Last_Week_Sales_Comparison =
VAR CurrentWeekNumber = WEEKNUM(TODAY(), 2)
VAR LastWeekStartDate = TODAY() - WEEKDAY(TODAY(), 2) - 6
VAR LastWeekEndDate = TODAY() - WEEKDAY(TODAY(), 2)
VAR LastYearWeekNumber = CurrentWeekNumber - 1
VAR LastYearDate = EDATE(LastWeekStartDate, -12) // 12 months back for last year
VAR LastYearStartDate = STARTOFWEEK(LastYearDate, 2)
VAR LastYearEndDate = ENDOFWEEK(LastYearStartDate, 2)

RETURN
SUMX(
FILTER(
Sales,
Sales[Posting Date]>= LastWeekStartDate &&
Sales[Posting Date] <= LastWeekEndDate
),
Sales[Sales Amount]
) -
SUMX(
FILTER(
Sales,
Sales[Posting Date] >= LastYearStartDate &&
Sales[Posting Date] <= LastYearEndDate
),
Sales[Sales Amount]
)

The error I face,

Too many arguments were passed to the STARTOFWEEK function. The maximum argument count for the function is 1.

It seems like a mix of M code (PowerQuery) and DAX (PowerBI).

@DarrenMoat1,

STARTOFWEEK and ENDOFWEEK only accept one argument. They calculate the starting or ending date of the week based on a given date. They don’t support the additional parameter for specifying the first day of the week (like 2 for Monday).

Hi @HufferD

Thank you for your help, I guess the AI doesn’t work as well as I thought for newbies. I will remove the arguments and see how I go.