Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more
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}}
)
Check out the April 2025 Power BI update to learn about new features.
Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.