cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
wahlau
Frequent Visitor

How to add column base on time range for date

2018-12-30_18-16-16.pngHi, I am beginer in PowerBI, also do search in forum that any post about time range found all is more about HR counting Hour function, here I have sales data from POS and our business hour is 8am to next day Morning 4am restaurant, I try lot of formula base on sales date to get the actual business date, one of the report is Sold item Beer sales vs Daily delivery Beer = Wastage of Beer. if I count as normal day sure in accurate.

 

Any function can help me solve this issue and How my dashboard always show yesterday sales.

 

Thanks 

 

1 ACCEPTED SOLUTION

Hi @v-qiuyu-msft,

Thanks for reply and your solution not suitable for me, because my time range is from today 7am till tomorrow 6am = today date, however I have my own solution, let me share on it.

there will be 3 separate column for this, 

1.  Time = FORMAT(pos_retail_sales_dtls[recdate] ,"hh:mm:ss")

#Take out the time from rec_date.

2.  EndDay = IF (pos_retail_sales_dtls[Time] >= TIME ( 7, 0, 0 )&& pos_retail_sales_dtls[Time] < TIME ( 23, 59, 59 ),"0", IF (pos_retail_sales_dtls[Time] >= TIME ( 0, 0, 0 )&&pos_retail_sales_dtls[Time] < TIME ( 6, 0, 0 ),"-1"))

#Let filter timing 7am - 12 = 0 and 12 - 6am = 0-1 ; no matter what date is that, it should be 2nd value is -1 day

3. Date Select = if(pos_retail_sales_dtls[EndDay] = "-1" , pos_retail_sales_dtls[recdate]-1, pos_retail_sales_dtls[recdate])

#Final result example 1/1/2019 9am = 1/1/2019, 2/1/2019 1.20am = 1/1/2019

 2019-01-05_19-07-49.png

 

View solution in original post

2 REPLIES 2
v-qiuyu-msft
Community Support
Community Support

Hi @wahlau,

 

1. You can create a calculated column then change data type as datetime. 

 

StartTime = DATE ( YEAR ('Table2'[recdate] ), MONTH ( 'Table2'[recdate] ), DAY ( 'Table2'[recdate] ) )
& " 7:00:00"
 
q1.PNG
 
 
2. Create another calculated column, change data type to date. 
WorkDate = IF('Table2'[recdate]<='Table2'[StartTime],FORMAT(Table2[recdate]-1,"Short Date"),FORMAT('Table2'[recdate],"Short Date"))
 
q2.PNG
 
Best Regards,
Qiuyun Yu 
Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-qiuyu-msft,

Thanks for reply and your solution not suitable for me, because my time range is from today 7am till tomorrow 6am = today date, however I have my own solution, let me share on it.

there will be 3 separate column for this, 

1.  Time = FORMAT(pos_retail_sales_dtls[recdate] ,"hh:mm:ss")

#Take out the time from rec_date.

2.  EndDay = IF (pos_retail_sales_dtls[Time] >= TIME ( 7, 0, 0 )&& pos_retail_sales_dtls[Time] < TIME ( 23, 59, 59 ),"0", IF (pos_retail_sales_dtls[Time] >= TIME ( 0, 0, 0 )&&pos_retail_sales_dtls[Time] < TIME ( 6, 0, 0 ),"-1"))

#Let filter timing 7am - 12 = 0 and 12 - 6am = 0-1 ; no matter what date is that, it should be 2nd value is -1 day

3. Date Select = if(pos_retail_sales_dtls[EndDay] = "-1" , pos_retail_sales_dtls[recdate]-1, pos_retail_sales_dtls[recdate])

#Final result example 1/1/2019 9am = 1/1/2019, 2/1/2019 1.20am = 1/1/2019

 2019-01-05_19-07-49.png

 

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors