Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
Hi, Im struggling with a little challenge and hope some is able to solve it!
I have a calendar table with two columns:
Date | Is Workday |
2024-01-01 | 0 |
2024-01-02 | 1 |
2024-01-03 | 1 |
2024-01-04 | 1 |
... | ... |
I need to mark the second workday depending on the Is Workday column (not depending on day of week). So in case of January 2024 this would be the 3rd of January, because 1st is marked as non workday. I need to do this for the entire table for every month each second workday. It can be a 0/1 coding for 1 being the second workday.
Thanks in advance!
Solved! Go to Solution.
Calculated Column
SecondWorkday =
VAR CurrentMonth = MONTH('Calendar'[Date])
VAR CurrentYear = YEAR('Calendar'[Date])
VAR WorkdayRank =
RANKX(
FILTER(
'Calendar',
'Calendar'[Is Workday] = 1 &&
MONTH('Calendar'[Date]) = CurrentMonth &&
YEAR('Calendar'[Date]) = CurrentYear
),
'Calendar'[Date],
,
ASC
)
RETURN
IF(WorkdayRank = 2, 1, 0)
This approach dynamically calculates the second workday for every month in your table.
💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn
It works if I add a filter for Is Workday:
SecondWorkday =
VAR CurrentMonth = MONTH('Calendar'[Date])
VAR CurrentYear = YEAR('Calendar'[Date])
VAR WorkdayRank =
RANKX(
FILTER(
'Calendar',
'Calendar'[Is Workday] = 1 &&
MONTH('Calendar'[Date]) = CurrentMonth &&
YEAR('Calendar'[Date]) = CurrentYear
),
'Calendar'[Date],
,
ASC
)
RETURN
IF(WorkdayRank = 2 && 'Calendar'[Is Workday] = 1, 1, 0)
Calculated Column
SecondWorkday =
VAR CurrentMonth = MONTH('Calendar'[Date])
VAR CurrentYear = YEAR('Calendar'[Date])
VAR WorkdayRank =
RANKX(
FILTER(
'Calendar',
'Calendar'[Is Workday] = 1 &&
MONTH('Calendar'[Date]) = CurrentMonth &&
YEAR('Calendar'[Date]) = CurrentYear
),
'Calendar'[Date],
,
ASC
)
RETURN
IF(WorkdayRank = 2, 1, 0)
This approach dynamically calculates the second workday for every month in your table.
💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn
It works if I add a filter for Is Workday:
SecondWorkday =
VAR CurrentMonth = MONTH('Calendar'[Date])
VAR CurrentYear = YEAR('Calendar'[Date])
VAR WorkdayRank =
RANKX(
FILTER(
'Calendar',
'Calendar'[Is Workday] = 1 &&
MONTH('Calendar'[Date]) = CurrentMonth &&
YEAR('Calendar'[Date]) = CurrentYear
),
'Calendar'[Date],
,
ASC
)
RETURN
IF(WorkdayRank = 2 && 'Calendar'[Is Workday] = 1, 1, 0)
Hi thanks for your reply. It does not produce the right result though.
In March 2024 it results in:
Date | Is Workday | Result |
2024-03-01 | 1 | 0 |
2024-03-02 | 0 | 1 |
2024-03-03 | 0 | 1 |
2024-03-04 | 1 | 1 |
... |
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
121 | |
88 | |
79 | |
61 | |
58 |
User | Count |
---|---|
129 | |
114 | |
97 | |
73 | |
71 |