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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
yanzhao_LBS
Helper II
Helper II

how to generate a table to calculate the sum of the last 6 months?

for example I have a table

namemonthAmount 
A2022-222 
A2022-330 
A2022-522 
A2022-730 
A2022-940 
A2022-1018 
B2022-340 
B2022-412 
B2022-640 
B2022-722 
B2022-866 
B2022-1045 

 

I want to generate a new table to calculate like this(today is Nov,so the last 6 month should be from 2022-5 to 2022-10)

Namelast 6 month amount
A110
B173

 

And the data should be refreshed as time goes by.

 

Can someone help?

 

Thanks.

1 ACCEPTED SOLUTION
VahidDM
Super User
Super User

Hi @yanzhao_LBS 

 

Try the following code to create your new table:

Table 2 =
VAR _current_Date =
    TODAY ()
VAR _End_Of_Last_Month =
    EOMONTH ( _current_Date, -1 )
VAR _Start_of_5_monthago =
    EOMONTH ( _End_Of_Last_Month, -6 )
RETURN
    SUMMARIZE (
        FILTER (
            'Table',
            'Table'[month] <= _End_Of_Last_Month
                && 'Table'[month] > _Start_of_5_monthago
        ),
        [name],
        "last 6 month amount", SUM ( 'Table'[Amount] )
    )

 

VahidDM_0-1668396441974.png

 

 

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

Appreciate your Kudos!! 

Badges.jpg

LinkedIn | Twitter | Blog | YouTube 

View solution in original post

2 REPLIES 2
VahidDM
Super User
Super User

Hi @yanzhao_LBS 

 

Try the following code to create your new table:

Table 2 =
VAR _current_Date =
    TODAY ()
VAR _End_Of_Last_Month =
    EOMONTH ( _current_Date, -1 )
VAR _Start_of_5_monthago =
    EOMONTH ( _End_Of_Last_Month, -6 )
RETURN
    SUMMARIZE (
        FILTER (
            'Table',
            'Table'[month] <= _End_Of_Last_Month
                && 'Table'[month] > _Start_of_5_monthago
        ),
        [name],
        "last 6 month amount", SUM ( 'Table'[Amount] )
    )

 

VahidDM_0-1668396441974.png

 

 

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

Appreciate your Kudos!! 

Badges.jpg

LinkedIn | Twitter | Blog | YouTube 

Thanks for your help,it works perfectly

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.