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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.