Forum Discussion
date data display
- 2 years ago
Hello kell,
In your example "week" is week of month and "week 2" is month of year. "WeekDisplay Sort" concatenates year and week of month - avoid using it for sorting because (e.g.) week 1 of January and week 1 of February would have the same "WeekDisplay Sort" value. Instead, use year and week of year for sorting. Here is an example, and in the example I take Monday as the start of the week.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tcq5DQAgDASwXaiRAiEfsyD2XwMKxKVz4bUKKwmxlF2vLdmTI3nCo8Gd9BdwgAIqaKCD8bgP", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
#"Added Week" = Table.AddColumn(#"Changed Type", "Week", each Date.ToText( Date.StartOfWeek([Date], Day.Monday), [Format="dd/MM"] ) & "-" & Date.ToText( Date.EndOfWeek([Date], Day.Monday), [Format="dd/MM"] ), type text),
#"Added Week Number" = Table.AddColumn(#"Added Week", "Week Number", each Date.WeekOfYear( [Date], Day.Monday ), Int64.Type),
#"Added Week Sort" = Table.AddColumn(#"Added Week Number", "Week Sort", each Number.From( Date.ToText([Date],[Format="yyyy"]) & Text.End("00" & Text.From([Week Number]),2)), Int64.Type )
in
#"Added Week Sort"This gives the result...
Hope this helps.
Hi Anonymous,
Please use a calendar table and create a new calculated column like:
Week Range =
VAR __WeekStartDate = 'Date'[Date] - WEEKDAY('Date'[Date], 2) + 1
VAR __WeekEndDate = 'Date'[Date] + 7 - WEEKDAY('Date'[Date], 2)
VAR __result = FORMAT(__WeekStartDate, "dd/MM") & "-" & FORMAT(__WeekEndDate, "dd/MM")
RETURN
__result
Output:
Best Regards,
Gao
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data in the Power BI Forum -- China Power BI User Group
Hi Gao Anonymous
Thank you so much for your help. I got this result but however i cant sort it out even i click in sort chart but it did not work as yours.
Please help.
Many thanks Gao.
- Anonymous2 years agoNot applicable
Hi Anonymous ,
Create another new column in the calendar table to aid in sorting:
Week Range Sort = 'Calendar'[Year]*100 + 'Calendar'[Week]and the select the [Week Range] sort by the [Week Range Sort].
Sort one column by another column in Power BI - Power BI | Microsoft Learn
Best Regards,
Gao
Community Support Team- Anonymous2 years agoNot applicable
Hi Anonymous ,
Thank you for your idea, But my mistake, I dont know why it did not work as notice:
Many thanks
- Anonymous2 years agoNot applicable
Hi Anonymous ,
This error means that a WeekDisplay value that are bound to two or more values in WeekDisplay Sort, like this:
Attach a PBIX file for reference.
Best Regards,
Gao
Community Support Team