Forum Discussion

Einomi's avatar
Einomi
Helper V
3 years ago
Solved

Declare a variable in a step

Hi all,   I have the following code to add the ISO week number based on my column date, which is called DateProduced   AddWeekNo = Table.AddColumn(#"Colonnes renommées1", "Week No", ...
  • artemus's avatar
    artemus
    3 years ago

    oh sorry about that the date at the end should be removed:

    AddWeekNo = Table.AddColumn(#"Colonnes renommées1", "Week No", each 
                let date = [DateProduced] in
    if
                Number.RoundDown((Date.DayOfYear(date)-(Date.DayOfWeek(date, Day.Sunday)+1)+10)/7)=0
                then 
                Number.RoundDown((Date.DayOfYear(#date(Date.Year(date)-1,12,31))-(Date.DayOfWeek(#date(Date.Year(date)-1,12,31), Day.Sunday)+1)+10)/7)
                else if
    
    etc....

     in fact you should be able to just add this almost anywhere:

    let myVar = SomeCalculation in