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
Anonymous
Not applicable

Power Query - date group

Hi All

 

I have a list of dates TIme that i wanted to group by batch batch 1 and batch 2. currently im doing it in excel and not in power BI but i cant find a community for power query specific so I post it here apologies.

 

I have two dates column

ohraytyroo_0-1597764332535.png

 

when i load this as a table later in excel the intended outcome or what the table will only show are the dates that are todays date and untill 12am and it will be tagged as batch 1. the next refresh should include the other dates that are not included on the first refresh so basically todays date and from 12 am onwards. the batch is an additional column just to help with grouping.

 

any ideas how i can solve this challenge?

 

Thanks in advance.

 

 

 

 

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @Anonymous ,

 

If there is any misunderstanding, please let me know.

 

Do you mean this:

  • "datesssss" column are from your data source (for exammple, SQL Server) and when your first load the data, "Date Today" column is show the current date/time;
datesssss Date Today
2020/8/3 7:55:00 PM 2020/8/18 11:21:39 PM
2020/8/3 8:55:00 PM 2020/8/18 11:21:39 PM
... ...

 

  • when the next day you load the data again, new data are loaded in, and the value "Date Today" column add new rows of the load time but don't change the previous value.
datesssss Date Today
2020/8/3 7:55:00 PM 2020/8/18 11:21:39 PM   (the first load time, no change)
2020/8/3 8:55:00 PM 2020/8/18 11:21:39 PM   (no change)
... ...                                      (no change)
2020/8/4 7:55:00 PM 2020/8/19 10:58:23 PM    (the second load time)
2020/8/4 8:55:00 PM 2020/8/19 10:58:23 PM    (the second load time)
... ...                                       (the second load time)

 

If so, to my knowledge, it is not achieved currently.

If not, please share us more details.

 

Best Regards,

Icey

 

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

4 REPLIES 4
Icey
Community Support
Community Support

Hi @Anonymous ,

 

If there is any misunderstanding, please let me know.

 

Do you mean this:

  • "datesssss" column are from your data source (for exammple, SQL Server) and when your first load the data, "Date Today" column is show the current date/time;
datesssss Date Today
2020/8/3 7:55:00 PM 2020/8/18 11:21:39 PM
2020/8/3 8:55:00 PM 2020/8/18 11:21:39 PM
... ...

 

  • when the next day you load the data again, new data are loaded in, and the value "Date Today" column add new rows of the load time but don't change the previous value.
datesssss Date Today
2020/8/3 7:55:00 PM 2020/8/18 11:21:39 PM   (the first load time, no change)
2020/8/3 8:55:00 PM 2020/8/18 11:21:39 PM   (no change)
... ...                                      (no change)
2020/8/4 7:55:00 PM 2020/8/19 10:58:23 PM    (the second load time)
2020/8/4 8:55:00 PM 2020/8/19 10:58:23 PM    (the second load time)
... ...                                       (the second load time)

 

If so, to my knowledge, it is not achieved currently.

If not, please share us more details.

 

Best Regards,

Icey

 

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

Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

 

to show this best in Excel I would reccomend to add a new column and make the calculation there to show if its batch1 or batch2.

Here an example

let
    Source = Table.FromColumns({List.DateTimes(#datetime(2020,8,01,0,0,0),500,#duration(0,3,0,0))},{"Date"}),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type datetime}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Batch", each if [Date]>=#datetime(Date.Year(DateTime.FixedLocalNow()), Date.Month(DateTime.FixedLocalNow()),Date.Day(DateTime.FixedLocalNow()),0,0,0) and [Date]<=#datetime(Date.Year(DateTime.FixedLocalNow()), Date.Month(DateTime.FixedLocalNow()),Date.Day(DateTime.FixedLocalNow()),12,0,0) then "Batch1" else if [Date]>#datetime(Date.Year(DateTime.FixedLocalNow()), Date.Month(DateTime.FixedLocalNow()),Date.Day(DateTime.FixedLocalNow()),12,0,0) and [Date]<=#datetime(Date.Year(DateTime.FixedLocalNow()), Date.Month(DateTime.FixedLocalNow()),Date.Day(DateTime.FixedLocalNow()),23,59,59) then "Batch2" else "no batch")
in
    #"Added Custom"

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

 

Anonymous
Not applicable

the function table.partition seems better suited to meet this grouping need

 

 

 

let
    Source = Table.FromColumns({List.DateTimes(#datetime(2020,8,18,6,0,0),30,#duration(0,0,20,0))},{"d"}),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"d", type datetime}}),
    ampm=Table.Partition(#"Changed Type","d",2, (am)=>if am<= #datetime(2020,8,18,12,0,0)then 0 else 1)
in 
    ampm

 

 

image.png

 

 

 

 

image.png

 

 

 

 

image.png

edhans
Super User
Super User

Not sure exactly what you are looking for. This formula will return the number of days from Aug 17, 2020 vs the date in the date column.

Duration.Days(DateTime.Date([Date]) - #date(2020,8,17))

So Aug 18 would be batch 1, Aug 19 batch 2, Aug 20, batch 3.

If that is not what you are looking for, can you post some sample data (not an image) and expected results?

 

How to get good help fast. Help us help you.
How to Get Your Question Answered Quickly
How to provide sample data in the Power BI Forum 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

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.

Top Solution Authors
Top Kudoed Authors