Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi all,
I wanted to calculate a column in a tabel for week start date based on a year week number integer
as below..
YearWeek Start Of the Week (new calculated column based on YearWeek column)
20211 1/1/2021
20212 4/1/2021
20213 11/1/2021
....
....
202141 6/9/2021
202142 13/9/2021
is there any way I can do this. thanks for the help
@Anonymous
Solved! Go to Solution.
Simple enough with PQ,
let
Source = List.TransformMany({2021,2022}, each {1..Date.WeekOfYear(#date(_,12,31), Day.Monday)}, (x,y) => {Text.From(x)&"-"&Number.ToText(y,"00"), List.Max({#date(x,1,1), Date.StartOfWeek(#date(x,1,1)+Duration.From((y-1)*7),Day.Monday)})}),
#"Start of Week" = Table.FromRows(Source, {"yyyyww", "Start of Week"})
in
#"Start of Week"
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
Simple enough with PQ,
let
Source = List.TransformMany({2021,2022}, each {1..Date.WeekOfYear(#date(_,12,31), Day.Monday)}, (x,y) => {Text.From(x)&"-"&Number.ToText(y,"00"), List.Max({#date(x,1,1), Date.StartOfWeek(#date(x,1,1)+Duration.From((y-1)*7),Day.Monday)})}),
#"Start of Week" = Table.FromRows(Source, {"yyyyww", "Start of Week"})
in
#"Start of Week"
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
HI @amalrio
It would be better to add a calendar table to your model and use that.
BTW, Try this code:
Column =
Var _WN = FORMAT(right([YearWeek],LEN([YearWeek])-4),"####")
Var _MinYear = CALCULATE(left(min([YearWeek]),4),all('Table'))
Var _MaxYear = CALCULATE(left(Max([YearWeek]),4),all('Table'))
Var _Year = FORMAT(left([YearWeek],4),"####")
Var _DateT = filter(ADDCOLUMNS(calendar(Date(_MinYear,1,1),date(_MaxYear,12,31)),"Year",YEAR([Date]),"WeekN",WEEKNUM([Date]),"Day",format([Date],"ddd")),[Day]<>"Sat"&&[Day]<>"Sun")
Var _FirstDateWeek =ADDCOLUMNS(GROUPBY(_DateT,[WeekN],[Year],"Date",minx(CURRENTGROUP(),[Date])),"YW",CONCATENATE([Year],[WeekN]))
return
MAXX(filter(_FirstDateWeek,VALUE([YW])=[YearWeek]),[Date])
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
113 | |
99 | |
80 | |
70 | |
59 |
User | Count |
---|---|
149 | |
114 | |
107 | |
89 | |
67 |