Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
tenfingers
Advocate II
Advocate II

Slicing a time range across two dates

I have a report where I need to slice the business hours which are 6am to 1am the following day. I only need to look at one business period at a time. I currently have a seperate date table and a time table. Looking for some ideas on how I can slice certain times one day and different times the following day or any suggestions on dealing with a time period that spans to different dates.
Cheers
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

 

I am hoping you have a timestamp column. Or the date and time stamp column. Based on that have these two columns

 


Bucket Date = if(hour([Timestamp])<=1, [Timestamp].date-1, [Timestamp].date)
Bucket = switch(true(),
hour([Timestamp])<=1 || hour([Timestamp])>=18 , "6PM to 1AM",
/// Othe bucket logic
)

@tenfingers 

View solution in original post

8 REPLIES 8
Greg_Deckler
Super User
Super User

Can you provide some sample data and expected output? Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thanks for the replies.

 

Model is simple date and time table connected to sales facts and and another shift fact table:

 

model.png

 

I guess I am looking for a modelling approach that will let me filter a report page to be 6am to 1am and allow me to use these times on the axis of a line chart:

 

line chart.png

 

Cheers

Right @tenfingers  but I am looking to not have to type a bunch of data that may or may not be representative of your actual data formats in order to test out a solution. 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thanks Greg,

 

I am using a date table with the datekey column connecting to my fact tables:

date table.png

 

This is my Time Table where time_id connects to the fact table:

 

time table.png

 

This is my sales fact with the timeid that connects the time table:

 

sales fact.png

 

Here is the rest of sales fact table with date id that connects the date table:

 

sales fact 2.png

 

I have a measure that sums sales from the sales fact table and would like to plot this on a line chart with hours 6am to 1am on the X axis. I would also like to be able to filter report pages to this range. Let me know if you need any more details.

 

Thanks in advance.

 

 

 

Slightly embarrassing, I think there’s a very simple solution: a calculated column with a conditional statement on the date and time in the fact table should do the trick to filter all sales in the required time period. I was so hung up on using my date and time tables to filter that I couldn’t see simple solution. Thanks anyway for taking the time to look at this.
Cheers

Glad you found a solution @tenfingers . Nothing to be embarrassed about. Sometimes stepping away from the problem for a bit and approaching it again with a fresh set of eyes is the way to go!


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
amitchandak
Super User
Super User

 

I am hoping you have a timestamp column. Or the date and time stamp column. Based on that have these two columns

 


Bucket Date = if(hour([Timestamp])<=1, [Timestamp].date-1, [Timestamp].date)
Bucket = switch(true(),
hour([Timestamp])<=1 || hour([Timestamp])>=18 , "6PM to 1AM",
/// Othe bucket logic
)

@tenfingers 

Thanks @amitchandak, this is the logic I used in the end.

Cheers

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.