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
daanp
Helper I
Helper I

How to create rows based on dates on seperate rows?

Hi all,

 

I'm trying to create an inventory table. 

 

Currently i have this:

user          date          Key

John1/2/20165
Jane3/2/20165
John6/2/20165
Mike8/2/20165

 

 

What i need is this:

user         date           Key

John1/2/20165
John2/2/20165
Jane3/2/20165
Jane4/2/20165
Jane5/2/20165
John6/2/20165
John7/2/20165
Mike8/2/20165

 

so i need to add rows with the missing dates and fill down the Users and Key. 

 

any advice on how i can accomplish this with power query?

3 REPLIES 3
TomMartens
Super User
Super User

Hey,

 

the little secret is M function List.Dates() ...

Here you will find a little pbix file

In the Query Editor I added a custom column using this function

List.Dates([Date],[Index], #duration(1,0,0,0))

After expanding the column to new rows you will receive what you are looking for

List.Dates.png

 

Hope this gets you started

 

Regards

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
MarcelBeug
Community Champion
Community Champion

It requires some coding (steps Custom1 and Custom2 below).

 

Transform the dates to numbers, and make a list from the minimum value to the maximum value.

Turn this into a table.

Now you can use standard menu-options:

Transform numbers back to dates.

Merge with the original table and fill down the missing values.

 

let
    Source = Table1,
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", Int64.Type}}),
    Custom1 = {List.Min(#"Changed Type"[Date])..List.Max(#"Changed Type"[Date])},
    Custom2 = Table.FromColumns({Custom1},{"date"}),
    #"Changed Type1" = Table.TransformColumnTypes(Custom2,{{"date", type date}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type1",{"date"},Table1,{"Date"},"Table1",JoinKind.LeftOuter),
    #"Expanded Table1" = Table.ExpandTableColumn(#"Merged Queries", "Table1", {"user", "Key"}, {"user", "Key"}),
    #"Filled Down" = Table.FillDown(#"Expanded Table1",{"user", "Key"})
in
    #"Filled Down"

 

Specializing in Power Query Formula Language (M)

Hi Marcel,

 

Thanks for your quick reply.

 

Your solution works for the dataset i provided.

 

However, i forgot to mention something. The dataset contains different keys with the same dates:

 

Jane3-2-20165
John6-2-20165
Mike8-2-20165
John1-2-20166
Jane3-2-20166
Mike8-2-20166

 

and i need:

 

   
Jane3-2-20165
Jane4-2-20165
Jane5-2-20165
John6-2-20165
John7-2-20165
Mike8-2-20165
John1-2-20166
John2-2-20166
Jane3-2-20166
Jane4-2-20166
Jane5-2-20166
Jane6-2-20166
Jane7-2-20166
Mike8-2-20166

 

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.