Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I am trying to create a week index for Power Query.
Any thoughts or if I am using the incorrect calculations?
M Code | StartOfCurrentWeek = Table.TransformColumnTypes(Table.AddColumn(#"Fiscal Year Status", "StartOfCurrentWeek", each Date.StartOfWeek(DateTime.FixedLocalNow(),+1)), {{"StartOfCurrentWeek", type date}}), StartOfWeek = Table.TransformColumnTypes(Table.AddColumn(StartOfCurrentWeek, "StartOfWeek", each Date.StartOfWeek([DateKey], 1)), {{"StartOfWeek", type date}}), #"Fiscal Week Index" = Table.TransformColumnTypes(Table.AddColumn(StartOfWeek, "Fiscal Week Index", each [StartOfWeek] - [StartOfCurrentWeek]), {{"Fiscal Week Index", Int64.Type}}), |
Screenshot |
|
Solved! Go to Solution.
7 or -7 is the difference in days, not weeks, so just divide by 7.
#"Fiscal Week Index" = Table.TransformColumnTypes(
Table.AddColumn(
StartOfWeek,
"Fiscal Week Index",
each ([StartOfWeek] - [StartOfCurrentWeek]) / 7
),
{{"Fiscal Week Index", Int64.Type}}
)
7 or -7 is the difference in days, not weeks, so just divide by 7.
#"Fiscal Week Index" = Table.TransformColumnTypes(
Table.AddColumn(
StartOfWeek,
"Fiscal Week Index",
each ([StartOfWeek] - [StartOfCurrentWeek]) / 7
),
{{"Fiscal Week Index", Int64.Type}}
)