Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!
Hello,
I would like to transform this DAX code in an add column statement in M language
YearWeekNo =
VAR FirstDayOfWeek = 1 -- Use: 0 para Domingo, 1 para Segunda, ..., 6 para Sábado
VAR FirstSundayReference = DATE(1990; 12; 30) -- Não Alterar
VAR CalDate = 'Calendar'[Date] -- Data a computar
VAR FirtWeekReference = FirstSundayReference + FirstDayOfWeek
VAR YearWeekNumber = INT(DIVIDE(CalDate -FirtWeekReference;7))
RETURN
YearWeekNumber
Thanks in advance
Solved! Go to Solution.
I just figured it out:
let
refDate = Date.AddDays(#date(1990,12,30), 1),
Source = List.Dates(#date(2018, 1, 1), 730, #duration(1, 0, 0, 0)),
toTable = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
colRename = Table.RenameColumns(toTable,{{"Column1", "Data"}}),
typeChange = Table.TransformColumnTypes(colRename,{{"Data", type date}}),
addYear = Table.AddColumn(typeChange, "Ano", each Date.Year([Data]), Int64.Type),
addMonth = Table.AddColumn(addYear, "Mês", each Date.Month([Data]), Int64.Type),
addMonthName = Table.AddColumn(addMonth, "Nome do Mês", each Date.MonthName([Data]), type text),
addDay = Table.AddColumn(addMonthName, "Dia", each Date.Day([Data]), Int64.Type),
addWeekCont = Table.AddColumn(addDay, "SemanaSeq", each Number.IntegerDivide(Duration.Days([Data]-refDate),7))
in
addWeekCont
Thanks in advance
Here you go. Something like this
(Date.StartOfWeek([Date], 1) - Date.StartOfWeek(Date.StartOfYear([Date]), 1)) / #duration(7, 0, 0, 0)
Sorry,
The DAX formula creates a sequential number of weeks since a predetermined date without starting over each year; like this:
I just figured it out:
let
refDate = Date.AddDays(#date(1990,12,30), 1),
Source = List.Dates(#date(2018, 1, 1), 730, #duration(1, 0, 0, 0)),
toTable = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
colRename = Table.RenameColumns(toTable,{{"Column1", "Data"}}),
typeChange = Table.TransformColumnTypes(colRename,{{"Data", type date}}),
addYear = Table.AddColumn(typeChange, "Ano", each Date.Year([Data]), Int64.Type),
addMonth = Table.AddColumn(addYear, "Mês", each Date.Month([Data]), Int64.Type),
addMonthName = Table.AddColumn(addMonth, "Nome do Mês", each Date.MonthName([Data]), type text),
addDay = Table.AddColumn(addMonthName, "Dia", each Date.Day([Data]), Int64.Type),
addWeekCont = Table.AddColumn(addDay, "SemanaSeq", each Number.IntegerDivide(Duration.Days([Data]-refDate),7))
in
addWeekCont
Thanks in advance
Vote for your favorite vizzies from the Power BI World Championship submissions!
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
Check out the January 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 11 | |
| 9 | |
| 8 | |
| 7 | |
| 6 |