Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Fcoatis
Post Patron
Post Patron

New Colum

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

1 ACCEPTED 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 

View solution in original post

3 REPLIES 3
artemus
Microsoft Employee
Microsoft Employee

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:

 

Continuous week.PNG

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 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.