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

DAX Generate statement to self join a table

Hi,

 

I'm trying to join a date table to itself using a >= operator.  The date table contains Period End Dates, and contains only a single column, which is the DateKey in integer format (ex: 20190131).  The combined date table should contain two columns.  The first column is the original DateKey, and the second column is each DateKey that is >= the original date key.  Ex: Let's say the table contains three Period End Dates: 20190131, 20181231, and 20181130.  The combined date table would look like this:

 

DateKey1     DateKey2

20190131     20190131

20190131     20181231

20190131     20181130

20181231     20181231

20181231     20181130

20181130     20181130

 

If they were two separate date tables, I could use a GENERATE statement to achieve the result.  This works:

 

GENERATE(DateTable1, SUMMARIZE(FILTER(DateTable2,DateTable2[DateKey] <= DateTable1[DateKey]),DateTable2[DateKey]))

 

However, if I just reference DateTable1, I get an error that the GENERATE does not allow two columns with the same name:

 

GENERATE(DateTable1, SUMMARIZE(FILTER(DateTable1,DateTable1[DateKey] <= DateTable1[DateKey]),DateTable1[DateKey]))

 

 

I'm looking for suggestions about how to code this statement without needing two versions of the table.

 

Thanks for any help.

 

1 ACCEPTED SOLUTION
LivioLanzo
Solution Sage
Solution Sage

Hello @Anonymous

 

try this:

 

Table = 
GENERATE(
    Data,
    SELECTCOLUMNS(
        CALCULATETABLE(
            VALUES( Data[DateKey] ),
            Data[DateKey] >= EARLIER( Data[DateKey] )
        ),
        "DateKey2", Data[DateKey]
    )
)

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

View solution in original post

2 REPLIES 2
LivioLanzo
Solution Sage
Solution Sage

Hello @Anonymous

 

try this:

 

Table = 
GENERATE(
    Data,
    SELECTCOLUMNS(
        CALCULATETABLE(
            VALUES( Data[DateKey] ),
            Data[DateKey] >= EARLIER( Data[DateKey] )
        ),
        "DateKey2", Data[DateKey]
    )
)

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

Anonymous
Not applicable

Thank you - that worked

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.