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
pouryas7
New Member

expanding dates in a period and add those dates to the rows

Hello,

 

In my table, I have Start_Date and EndDate. I want to expand the dates in between.

Let's say:

ID    Start_date     End_Date

1     2018/01/01   2018/01/03

 

I want this:

ID  Date

1    2018/01/01

1    2018/01/02

1    2018/01/03

 

I tried to use this DAX function (Add column feature in dashboard):

DATESINPERIOD( DimDate[FullDate],[START_DATE],[NUM_DAYS],DAY)

 

But, it gave me this error:

A table of multiple values was supplied where a single value was expected.

 

Well, I have a table named DimDate and NUM_DAYS is the number of days between start and end date.

 

Thanks!

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @pouryas7

 

To create this table using DAX, you would have to click New Table rather than New Column.

Adding a column can only add a column using a scalar expression, preserving the number of rows.

 

To create this expanded table, you would need to create a table with an expression like this (assuming DimDate contains all required dates):

 

Expanded Table =
SELECTCOLUMNS (
    GENERATE (
        ExistingTable,
        DATESBETWEEN (
            DimDate[FullDate],
            ExistingTable[Start_date],
            ExistingTable[End_Date]
        )
    ),
    "ID", ExistingTable[ID],
    "Date", DimDate[FullDate]
)

Alternatively, you could use the CALENDAR function to generate the sequences of dates without relying on DimDate:

Expanded Table =
SELECTCOLUMNS (
    GENERATE (
        ExistingTable,
        CALENDAR ( ExistingTable[Start_date], ExistingTable[End_Date] )
    ),
    "ID", ExistingTable[ID],
    "Date", [Date]
)

Regards,

Owen

 


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

1 REPLY 1
OwenAuger
Super User
Super User

Hi @pouryas7

 

To create this table using DAX, you would have to click New Table rather than New Column.

Adding a column can only add a column using a scalar expression, preserving the number of rows.

 

To create this expanded table, you would need to create a table with an expression like this (assuming DimDate contains all required dates):

 

Expanded Table =
SELECTCOLUMNS (
    GENERATE (
        ExistingTable,
        DATESBETWEEN (
            DimDate[FullDate],
            ExistingTable[Start_date],
            ExistingTable[End_Date]
        )
    ),
    "ID", ExistingTable[ID],
    "Date", DimDate[FullDate]
)

Alternatively, you could use the CALENDAR function to generate the sequences of dates without relying on DimDate:

Expanded Table =
SELECTCOLUMNS (
    GENERATE (
        ExistingTable,
        CALENDAR ( ExistingTable[Start_date], ExistingTable[End_Date] )
    ),
    "ID", ExistingTable[ID],
    "Date", [Date]
)

Regards,

Owen

 


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

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.