Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
I need the calendar table to be created in Power BI as in the image. It has to be dynamic for each year.
Can anyone help me with this?
Hi @priyamsachan12 ,
1. According to your description, I created the date table.
Table =
Calendar (
Date (2024,1,1),
Date (2024,4,30)))
2. Create the calculation column.
Weeknum =
Weeknum ('table' [date], 2)
3. Create the calculation column.
Weekday =
Weekday ('Table' [Date], 2)
4. Create the calculation column to get the order of this month.
Week =
RANKX (RANKX
Filter (all ('table'),
Year ('table' [date]) = year (earlier ('table' [date])) && Month ('table' [date]) = month (earlier ('table' [date])), [weeknum], , ASC, DENSE)
5.Create the calculation column.
Column =
var _count=
COUNTX(
FILTER(ALL('Table'),
YEAR('Table'[Date])=YEAR(EARLIER('Table'[Date]))&&MONTH('Table'[Date])=MONTH(EARLIER('Table'[Date]))&&'Table'[Week]=1),[Date])
return
IF(
_count<4&&'Table'[Week]=1,_count +7,
IF(
_count>=4&&'Table'[Week]=1,_count,_count))
6. Create the calculation column to get the date of different weeks.
Test =
var _mindate=
MINX(FILTER(ALL('Table'),YEAR('Table'[Date])=YEAR(EARLIER('Table'[Date]))&&MONTH('Table'[Date])=MONTH(EARLIER('Table'[Date]))&&'Table'[Week]=EARLIER('Table'[Week])),
[Date])
var _maxdate=
MAXX(FILTER(ALL('Table'),YEAR('Table'[Date])=YEAR(EARLIER('Table'[Date]))&&MONTH('Table'[Date])=MONTH(EARLIER('Table'[Date]))&&'Table'[Week]=EARLIER('Table'[Week])),
[Date])
var _maxweek=
MAXX(FILTER(ALL('Table'),YEAR('Table'[Date])=YEAR(EARLIER('Table'[Date]))&&MONTH('Table'[Date])=MONTH(EARLIER('Table'[Date]))),[Week])
var _count=COUNTX(
FILTER(ALL('Table'),
YEAR('Table'[Date])=YEAR(EARLIER('Table'[Date]))&&MONTH('Table'[Date])=MONTH(EARLIER('Table'[Date]))&&'Table'[Week]=1),[Date])
var _value=_mindate+6
var _if=
IF(
_value>_maxdate,_maxdate,_value)
return
SWITCH(
TRUE(),
[Week]=_maxweek&&[Column]<4,"blank",
[Column]>7,_mindate&"-"&_mindate+[Column]-1,
[Column]=7,_mindate&"-"&_if,
[Column]>3&&[Column]<7,_mindate&"-"&_if,
[Column]<=3,_mindate+7&"-"&_mindate+7+6
)
If your Current Period does not refer to this, please clarify in a follow-up reply.
Best Regards,
Clara Gong
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks for the response.
I want the calendar table from above image not exactly the columns as image.
Logic: Week1 Should have more than 4 days else it will end on next sunday and last week should have min. 3 days else it will be merged with its previous week.
Reference Table:
Below is the output table expected in Power BI.
Year | Month | WeekStartDate | WeekEndDate | WeekNumber |
2024 | January | 01-01-2024 | 07-01-2024 | 1 |
2024 | January | 08-01-2024 | 14-01-2024 | 2 |
2024 | January | 15-01-2024 | 21-01-2024 | 3 |
2024 | January | 22-01-2024 | 28-01-2024 | 4 |
2024 | January | 29-01-2024 | 31-01-2024 | 5 |
2024 | February | 01-02-2024 | 11-02-2024 | 1 |
2024 | February | 12-02-2024 | 18-02-2024 | 2 |
2024 | February | 19-02-2024 | 25-02-2024 | 3 |
2024 | February | 26-02-2024 | 29-02-2024 | 4 |
2024 | March | 01-03-2024 | 10-03-2024 | 1 |
2024 | March | 11-03-2024 | 17-03-2024 | 2 |
2024 | March | 18-03-2024 | 24-03-2024 | 3 |
2024 | March | 25-03-2024 | 31-03-2024 | 4 |
2024 | April | 01-04-2024 | 07-04-2024 | 1 |
2024 | April | 08-04-2024 | 14-04-2024 | 2 |
2024 | April | 15-04-2024 | 21-04-2024 | 3 |
2024 | April | 22-04-2024 | 30-04-2024 | 4 |
2024 | May | 01-05-2024 | 05-05-2024 | 1 |
2024 | May | 06-05-2024 | 12-05-2024 | 2 |
2024 | May | 13-05-2024 | 19-05-2024 | 3 |
2024 | May | 20-05-2024 | 26-05-2024 | 4 |
2024 | May | 27-05-2024 | 31-05-2024 | 5 |
2024 | June | 01-06-2024 | 09-06-2024 | 1 |
2024 | June | 10-06-2024 | 16-06-2024 | 2 |
2024 | June | 17-06-2024 | 23-06-2024 | 3 |
2024 | June | 24-06-2024 | 30-06-2024 | 4 |
2024 | July | 01-07-2024 | 07-07-2024 | 1 |
2024 | July | 08-07-2024 | 14-07-2024 | 2 |
2024 | July | 15-07-2024 | 21-07-2024 | 3 |
2024 | July | 22-07-2024 | 28-07-2024 | 4 |
2024 | July | 29-07-2024 | 31-07-2024 | 5 |
2024 | August | 01-08-2024 | 11-08-2024 | 1 |
2024 | August | 12-08-2024 | 18-08-2024 | 2 |
2024 | August | 19-08-2024 | 25-08-2024 | 3 |
2024 | August | 26-08-2024 | 31-08-2024 | 4 |
2024 | September | 01-09-2024 | 11-09-2024 | 1 |
2024 | September | 09-09-2024 | 15-09-2024 | 2 |
2024 | September | 16-09-2024 | 22-09-2024 | 3 |
2024 | September | 23-09-2024 | 30-09-2024 | 4 |
2024 | October | 01-10-2024 | 06-10-2024 | 1 |
2024 | October | 07-10-2024 | 13-10-2024 | 2 |
2024 | October | 14-10-2024 | 20-10-2024 | 3 |
2024 | October | 21-10-2024 | 27-10-2024 | 4 |
2024 | October | 28-10-2024 | 31-10-2024 | 5 |
2024 | November | 01-11-2024 | 10-11-2024 | 1 |
2024 | November | 11-11-2024 | 17-11-2024 | 2 |
2024 | November | 18-11-2024 | 24-11-2024 | 3 |
2024 | November | 25-11-2024 | 30-11-2024 | 4 |
2024 | December | 01-12-2024 | 08-12-2024 | 1 |
2024 | December | 09-12-2024 | 15-12-2024 | 2 |
2024 | December | 16-12-2024 | 22-12-2024 | 3 |
2024 | December | 23-12-2024 | 31-12-2024 | 4 |
User | Count |
---|---|
119 | |
78 | |
58 | |
52 | |
46 |
User | Count |
---|---|
170 | |
117 | |
63 | |
58 | |
51 |