cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Freeseman
Helper II
Helper II

Date sort from 18:00 to 17:00

Hi All,

 

Is there a way to sort my date in 24h day from 18:00 start to 17:00 end and not from 00:00 to 23:00

So in other words like this...

Freeseman_1-1660049407457.png

I am trying to structure my X axis by hour but in a specific order. So by default Power BI would arrange my hours from 0 - 23

or it would kind of just mix them up as below.

Freeseman_0-1660049351800.png

The result i am trying to acheive is like this:

Freeseman_1-1660049407457.png

Please help me in the right direction to replicate the second visual

1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

Hi @Freeseman ,

 

Please try:

First, create a new column to help sort:

vjianbolimsft_1-1660633780556.png

 

Here is the M code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tc/JDcAwCATAXnj7YRYfoRYr/bcRsY4Ev7E4Fp8jXZq4yduOaHCRCHbSgiBHcJMzOMiVYzt7n+AkvUREnPa7WRno1yi23KijDsxSWLWw64PReu2lgJ5HQ7MJyH/B/jveDw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Time = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Time", Int64.Type}, {"Value", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Time]>=18 then [Time]-18 else [Time]+6),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Custom", Int64.Type}})
in
    #"Changed Type1"

Then use sort by column:

vjianbolimsft_2-1660633868312.png

Choose sort by time in the visual:

vjianbolimsft_3-1660634078990.png

Final output:

vjianbolimsft_4-1660634108257.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

1 REPLY 1
v-jianboli-msft
Community Support
Community Support

Hi @Freeseman ,

 

Please try:

First, create a new column to help sort:

vjianbolimsft_1-1660633780556.png

 

Here is the M code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tc/JDcAwCATAXnj7YRYfoRYr/bcRsY4Ev7E4Fp8jXZq4yduOaHCRCHbSgiBHcJMzOMiVYzt7n+AkvUREnPa7WRno1yi23KijDsxSWLWw64PReu2lgJ5HQ7MJyH/B/jveDw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Time = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Time", Int64.Type}, {"Value", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Time]>=18 then [Time]-18 else [Time]+6),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Custom", Int64.Type}})
in
    #"Changed Type1"

Then use sort by column:

vjianbolimsft_2-1660633868312.png

Choose sort by time in the visual:

vjianbolimsft_3-1660634078990.png

Final output:

vjianbolimsft_4-1660634108257.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

Helpful resources

Announcements
September Update

Check it Out!

Click here to learn more about the September 2022 updates!

Power BI Show Episode 10 Recap

The Power BI Community Show

Watch the playback when Amit Chandak, a Power BI Super User, demos how to use Field Parameters to make reports more dynamic.

Power BI Dev Camp Session 26

New Date - Check it Out!

Mark your calendars and join us on Thursday, October 6 at 11a PDT for a great session with Ted Pattison!

Health and Life Sciences Power BI User Group

Health and Life Sciences Power BI User Group

Power BI specialists at Microsoft have created a community user group where customers in the provider, payor, pharma, health solutions, and life science industries can collaborate.

Top Solution Authors
Top Kudoed Authors