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
tanquoc0309
Helper II
Helper II

Expand table with condition

I have 2 tables - invoice and Dimdate

 

InvoiceIDPeriod StartPeriod End
129 Jun 201902 Jul 2019
21 Sep 20192 Sep 2019
34 Sep 20194 Sep 2019

 

How can I create a new table as below:

InvoiceIDDatePeriod StartPeriod End
129-Jun-1929-Jun-192-Jul-19
130-Jun-1929-Jun-192-Jul-19
11-Jul-1929-Jun-192-Jul-19
12-Jul-1929-Jun-192-Jul-19
21-Sep-191-Sep-192-Sep-19
22-Sep-191-Sep-192-Sep-19
34-Sep-194-Sep-194-Sep-19

 

1 ACCEPTED SOLUTION
v-frfei-msft
Community Support
Community Support

Hi @tanquoc0309 ,

 

We can create a calculated table as below.

Table 2 = 
VAR a =
    ADDCOLUMNS (
        CROSSJOIN (
            'Table',
            CALENDAR ( MIN ( 'Table'[PeriodStart] ), MAX ( 'Table'[PeriodEnd] ) )
        ),
        "s", 'Table'[PeriodStart],
        "e", 'Table'[PeriodEnd]
    )
VAR ad =
    ADDCOLUMNS ( a, "c", IF ( [Date] >= [s] && [Date] <= [e], 1, BLANK () ) )
RETURN
    SELECTCOLUMNS (
        FILTER ( ad, [c] = 1 ),
        "id", 'Table'[InoviceID],
        "st", 'Table'[PeriodStart],
        "end", 'Table'[PeriodEnd],
        "Date", [Date]
    )

Capture.PNG

 

PBIX as attached.

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

2 REPLIES 2
v-frfei-msft
Community Support
Community Support

Hi @tanquoc0309 ,

 

We can create a calculated table as below.

Table 2 = 
VAR a =
    ADDCOLUMNS (
        CROSSJOIN (
            'Table',
            CALENDAR ( MIN ( 'Table'[PeriodStart] ), MAX ( 'Table'[PeriodEnd] ) )
        ),
        "s", 'Table'[PeriodStart],
        "e", 'Table'[PeriodEnd]
    )
VAR ad =
    ADDCOLUMNS ( a, "c", IF ( [Date] >= [s] && [Date] <= [e], 1, BLANK () ) )
RETURN
    SELECTCOLUMNS (
        FILTER ( ad, [c] = 1 ),
        "id", 'Table'[InoviceID],
        "st", 'Table'[PeriodStart],
        "end", 'Table'[PeriodEnd],
        "Date", [Date]
    )

Capture.PNG

 

PBIX as attached.

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
bharathvee
Frequent Visitor

Hi, can u post both the tables you have?

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