Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by watching the DP-600 session on-demand now through April 28th.
Learn moreJoin the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register 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
Check out the April 2026 Power BI update to learn about new features.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 5 | |
| 3 | |
| 3 | |
| 3 | |
| 3 |
| User | Count |
|---|---|
| 8 | |
| 6 | |
| 5 | |
| 5 | |
| 4 |