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.
Hi,
I would like to create a calculated column to create batches based on date and time. For example:
01/01/2022 11:00:00 AM to 01/02/2022 11:00:00AM Batch1
01/02/2022 11:00:00 AM to 01/03/2022 11:00:00AM Batch2
01/03/2022 11:00:00 AM to 01/04/2022 11:00:00AM Batch3
The logic should look for the next available date in the table and assign next batch number for current date to next available date and 24 hours difference.
Thanks for any ideas.
Solved! Go to Solution.
if you just want to select the dates in your table (May skip Weekends, holidays ect)
Add Conditional Column to table in Power Query:
= Table.AddColumn(#"Renamed Columns", "Adj Date", each if [Time] >= #time(11, 0, 0) then [Date] else (Date.AddDays([Date],-1)))
Create a Copy of your Table in Power Query name it Batch
Remove all Columns except for Adj Date
Remove duplicates
add index starting at 1 this will be your batch number
Join to your financials table: [Adj Date] --> Batch Table: [Adj Date]
change index field to not summarize
Hi, @adityamalik1234 ;
Such as kitgo2 said, you could create a column by dax.
Column = "Batch"&IF(TIME(HOUR( [datetime]),MINUTE( [datetime]),SECOND( [datetime]))<TIME(11,0,0),DAY([datetime])-1,DAY([datetime]))
The final show:
Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
You might be able use the Day of the month or day of the year for your batch number:
if you just want to select the dates in your table (May skip Weekends, holidays ect)
Add Conditional Column to table in Power Query:
= Table.AddColumn(#"Renamed Columns", "Adj Date", each if [Time] >= #time(11, 0, 0) then [Date] else (Date.AddDays([Date],-1)))
Create a Copy of your Table in Power Query name it Batch
Remove all Columns except for Adj Date
Remove duplicates
add index starting at 1 this will be your batch number
Join to your financials table: [Adj Date] --> Batch Table: [Adj Date]
change index field to not summarize
This is how the data looks like:
1/1/2022 9:00 |
1/1/2022 10:00 |
1/1/2022 11:00 |
1/1/2022 12:00 |
1/1/2022 13:00 |
1/1/2022 14:00 |
1/1/2022 15:00 |
1/1/2022 16:00 |
2/1/2022 9:00 |
2/1/2022 10:00 |
2/1/2022 11:00 |
2/1/2022 12:00 |
2/1/2022 13:00 |
2/1/2022 14:00 |
2/1/2022 15:00 |
2/1/2022 16:00 |
3/1/2022 9:00 |
3/1/2022 10:00 |
3/1/2022 11:00 |
3/1/2022 12:00 |
3/1/2022 13:00 |
3/1/2022 14:00 |
3/1/2022 15:00 |
3/1/2022 16:00 |
5/1/2022 9:00 |
5/1/2022 10:00 |
5/1/2022 11:00 |
5/1/2022 12:00 |
5/1/2022 13:00 |
5/1/2022 14:00 |
5/1/2022 15:00 |
5/1/2022 16:00 |
The calculated column should result in the following:
1/1/2022 9:00 | Batch 0 |
1/1/2022 10:00 | Batch 0 |
1/1/2022 11:00 | Batch 1 |
1/1/2022 12:00 | Batch 1 |
1/1/2022 13:00 | Batch 1 |
1/1/2022 14:00 | Batch 1 |
1/1/2022 15:00 | Batch 1 |
1/1/2022 16:00 | Batch 1 |
2/1/2022 9:00 | Batch 1 |
2/1/2022 10:00 | Batch 1 |
2/1/2022 11:00 | Batch 2 |
2/1/2022 12:00 | Batch 2 |
2/1/2022 13:00 | Batch 2 |
2/1/2022 14:00 | Batch 2 |
2/1/2022 15:00 | Batch 2 |
2/1/2022 16:00 | Batch 2 |
3/1/2022 9:00 | Batch 2 |
3/1/2022 10:00 | Batch 2 |
3/1/2022 11:00 | Batch 3 |
3/1/2022 12:00 | Batch 3 |
3/1/2022 13:00 | Batch 3 |
3/1/2022 14:00 | Batch 3 |
3/1/2022 15:00 | Batch 3 |
3/1/2022 16:00 | Batch 3 |
5/1/2022 9:00 | Batch 3 |
5/1/2022 10:00 | Batch 3 |
5/1/2022 11:00 | Batch 4 |
5/1/2022 12:00 | Batch 4 |
5/1/2022 13:00 | Batch 4 |
5/1/2022 14:00 | Batch 4 |
5/1/2022 15:00 | Batch 4 |
5/1/2022 16:00 | Batch 4 |
I am wondering if there is any way of doing this through switch or through loop functions?
you create a table 'Batches' which contains three columns [From], [To] and [Batch]
then the new calculated column in Table1 would be
MAXX (
FILTER ( Batches, Batches [From] <= Table1[Date] && Batches [To] > Table1[Date] ), Batches[Batch] )
Hi Tamerj,
thanks for your reply. I am looking for help on creating the logic for the Batch number. So the earliest date to next date is batch1 and so on.
Ok. Please share some sample data to understand how does it look like.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
99 | |
77 | |
66 | |
54 |
User | Count |
---|---|
144 | |
104 | |
102 | |
87 | |
64 |