Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi,
I made a Date table as following.
When select a YearMonth such as 2020/05, the visual will show its YearWeeknum.
However, I also want it show these YearWeeknum belongs to which date.
So I want to write a new column like the following:
For example, when select YearMonth 202005, it should be 2020/5/1-2020/5/3 (which is YearWeeknum 202018 in the previous bar chart.), 2020/5/4-2020/5/10, 2020/5/11-2020/5/17........
Anyone know how to write this new column in power bi?
Thanks a lot for your time!
Solved! Go to Solution.
Hi, @YunJ
I'd like to suggest you create a calculated column as below. The pbix file is attached in the end.
DateDuration =
var _min =
CALCULATE(
MIN('Date'[Date]),
FILTER(
ALL('Date'),
'Date'[YearWeeknum]=EARLIER('Date'[YearWeeknum])&&
'Date'[Month]=EARLIER('Date'[Month])
)
)
var _max =
CALCULATE(
MAX('Date'[Date]),
FILTER(
ALL('Date'),
'Date'[YearWeeknum]=EARLIER('Date'[YearWeeknum])&&
'Date'[Month]=EARLIER('Date'[Month])
)
)
return
_min&"-"&_max
Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, @YunJ
I'd like to suggest you create a calculated column as below. The pbix file is attached in the end.
DateDuration =
var _min =
CALCULATE(
MIN('Date'[Date]),
FILTER(
ALL('Date'),
'Date'[YearWeeknum]=EARLIER('Date'[YearWeeknum])&&
'Date'[Month]=EARLIER('Date'[Month])
)
)
var _max =
CALCULATE(
MAX('Date'[Date]),
FILTER(
ALL('Date'),
'Date'[YearWeeknum]=EARLIER('Date'[YearWeeknum])&&
'Date'[Month]=EARLIER('Date'[Month])
)
)
return
_min&"-"&_max
Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, @YunJ
I'd like to suggest you modify the calculated table as below.
Date =
ADDCOLUMNS(
ADDCOLUMNS(
CALENDAR(DATE(2020,1,1),DATE(2020,12,31)),
"Year",YEAR([Date]),
"Quarter","Q"&FORMAT([Date],"Q"),
"Month",FORMAT([Date],"MM"),
"Day",FORMAT([Date],"DD"),
"YearQuarter",FORMAT([Date],"YYYY")&"Q"&FORMAT([Date],"Q"),
"YearMonth",FORMAT([Date],"YYYY/MM"),
"Weekday",WEEKDAY([Date],2),
"Weeknum",WEEKNUM([Date],2)
),
"YearWeeknum",[Year]*100+[Weeknum],
"YearMonthWeeknum",[Year]*100+[Month]*10+[Weeknum]
)
Then you may make 'DateDuration' column selected, click 'Sort by column' in 'Column tools', sort by 'YearMonthWeeknum'.
Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
@YunJ , not very clear to me. Do need week start and end date
Week Start date = 'Date'[Date]+-1*WEEKDAY('Date'[Date],2)+1 //Monday start
Week End date = 'Date'[Date]+ 7-1*WEEKDAY('Date'[Date],2)
Week Start date = 'Date'[Date]+-1*WEEKDAY('Date'[Date],2)+1 //Sunday Start
Week End date = 'Date'[Date]+ 7-1*WEEKDAY('Date'[Date],2)
Week name = [Week Start date] & " to "& [Week End date]
Hi @YunJ ,
Please use the below one:
Measure = CALCULATE(MIN('Table'[Date]),ALL('Table'[Year],'Table'[Quarter],'Table'[Month],'Table'[Day],'Table'[YearQuarter],'Table'[YearMonth],'Table'[Weekday],'Table'[Weeknum],'Table'[Date])) & "-" & CALCULATE(MAX('Table'[Date]),ALL('Table'[Year],'Table'[Quarter],'Table'[Month],'Table'[Day],'Table'[YearQuarter],'Table'[YearMonth],'Table'[Weekday],'Table'[Weeknum],'Table'[Date]))
Aiolos Zhao
Hi @YunJ ,
Create a Column
Thanks for your help.
For example for 2020/5/3, because it belongs to May, so it should be 5/1/2020-5/3/2020. I want it return the start/end start for the month itself.
You need a if-else for this:
Measure = IF(CALCULATE(MIN('Table'[Date]),ALLEXCEPT('Table','Table'[YearWeeknum])) < STARTOFMONTH('Table'[Date]),STARTOFMONTH('Table'[Date]),CALCULATE(MIN('Table'[Date]),ALLEXCEPT('Table','Table'[YearWeeknum])))
& "-" &
IF(CALCULATE(MAX('Table'[Date]),ALLEXCEPT('Table','Table'[YearWeeknum])) > ENDOFMONTH('Table'[Date]),ENDOFMONTH('Table'[Date]),CALCULATE(MAX('Table'[Date]),ALLEXCEPT('Table','Table'[YearWeeknum])))
Aiolos Zhao
Hi @Anonymous
I'm wondering can this be sort in the correct order?
Thanks a lot for your time!
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
65 | |
63 | |
53 | |
39 | |
26 |
User | Count |
---|---|
85 | |
57 | |
45 | |
44 | |
36 |