Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Merge Table by itself

Hi all!

 

I want to create this table. Merge a table with the same table in order to create an extra column that is based on two keys: AccNum and the Date.

 

table merge.png

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

Hi, @Anonymous 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attacehd in the end.

Table:

d1.png

 

You may create a calculated column as below.

Result = 
var _lastvalue = 
CALCULATE(
    SUM('Table'[Total]),
    FILTER(
        'Table',
        'Table'[AccNum]=EARLIER('Table'[AccNum])&&
        'Table'[Date]=EARLIER('Table'[PreviousDate])
    )
)
return
COALESCE(_lastvalue,0)

 

Result:

d2.png

 

Or you can create a calculated table as below.

NewTable = 
ADDCOLUMNS(
    'Table',
    "Result2",
    var _lastvalue = 
    CALCULATE(
        SUM('Table'[Total]),
        FILTER(
            'Table',
            'Table'[AccNum]=EARLIER('Table'[AccNum])&&
            'Table'[Date]=EARLIER('Table'[PreviousDate])
        )
    )
    return
    COALESCE(_lastvalue,0)
)

 

Result:

d3.png

 

Best Regards

Allan

 

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
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attacehd in the end.

Table:

d1.png

 

You may create a calculated column as below.

Result = 
var _lastvalue = 
CALCULATE(
    SUM('Table'[Total]),
    FILTER(
        'Table',
        'Table'[AccNum]=EARLIER('Table'[AccNum])&&
        'Table'[Date]=EARLIER('Table'[PreviousDate])
    )
)
return
COALESCE(_lastvalue,0)

 

Result:

d2.png

 

Or you can create a calculated table as below.

NewTable = 
ADDCOLUMNS(
    'Table',
    "Result2",
    var _lastvalue = 
    CALCULATE(
        SUM('Table'[Total]),
        FILTER(
            'Table',
            'Table'[AccNum]=EARLIER('Table'[AccNum])&&
            'Table'[Date]=EARLIER('Table'[PreviousDate])
        )
    )
    return
    COALESCE(_lastvalue,0)
)

 

Result:

d3.png

 

Best Regards

Allan

 

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

amitchandak
Super User
Super User

@Anonymous , You can do that in new column using earlier

 

sumx(filter(table , [AccNum] = earlier([AccNum]) && [Date] = earlier([Date])),[Total])

 

Your logic is not clear. So not able to suggest the exact formula. You can treat earlier as new copy of same table

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

The logic is making an extra column that contains the totals from the previous month and then by subtracting them will find the difference (i.e. the movement inside the month) in order to use it for other calculations.

Pragati11
Super User
Super User

Hi @Anonymous ,

 

I would suggest doing this in Power BI Query Editor.

Duplicate your table and the choose Merge for these tables. 

Refer following article on how to merge tables in Power BI:

https://radacad.com/how-to-change-joining-types-in-power-bi-and-power-query

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.