Forum Discussion
custom column with switch statement
- 8 years ago
Then the Switch statement that you mentioned is working perfect right?
In this case as well, create two columns
Name of Day
= SWITCH(
WEEKDAY(table[Date],2),
1,"Monday",
2,"Tuesday",
3,"Wednesday",
4,"Thursday",
5,"Friday",
6,"Saturday",
7,"Sunday")and
Day of Week = WEEKDAY(table[Date],2)
Then use Sort by column option as suggested before.
- indhu8 years agoHelper III
thanks Phil_Seamark.
Actually, I have a date column and transformed that into a calculated day of the week by following,
1. Duplicated the column
2. right click -> transform -> Day -> day of week
after the above step i have this formula in the bar,
= Table.TransformColumns(#"Duplicated Column",{{"timestamp - Copy", Date.DayOfWeek, Int64.Type}}).If I follow as you suggested,
= Table.TransformColumns(#"Duplicated Column",format{{"timestamp - Copy", Date.DayOfWeek, Int64.Type,"DDDD"}}).This doesn't work. I know I am missing something stupid. Can you please help?
I read in a post that custom column is more efficient than a calculated column. So thought I can try that
Thanks again,
Indhu
- indhu8 years agoHelper III
Thanks Phil_Seamark
Actually, I have a date column which i am transforming in the following way,
1. Duplicate the actual date column
2. calculate the day of the week by right click -> Transform -> day -> day of week
Now I have a column with a day of the week in numbers and wanted to transform that into the name. One option will be to use replace values option. But I feel it is not an efficient way to do it.
Following your previous post,
= Table.DuplicateColumn(#"Renamed Columns2", "timestamp", "timestamp - Copy")
This will be the actual code and when using the format option with this,
= Table.DuplicateColumn(#"Renamed Columns2", "timestamp", format("timestamp - Copy","DDDD")I know something is wrong but can't find out what it is can you please put me in the right direction?
Thanks,
- anithat8 years agoResolver II
Hi Indhu
Have you tried to select "Name of Day" in the Transform option.
1. Duplicate the actual date column
2. calculate the day of the week by right click -> Transform -> day ->
day of weekName of DayIs that what you are Expecting?
- indhu8 years agoHelper III
anithat thanks for your reply. What you mentioned will fetch day name in text. This is what i expect but this makes sorting difficult.
The above result will only allow us to sort by alphabet which makes visuals weird. I wanted the visual to be ordered beginning from Monday. For this purpose, I used switch statement by manually using numbers at the beginning like "1.Monday".
I did this in a calculated column. Now trying to figure out in a custom column
Thanks,