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
yanzhao_LBS
Helper I
Helper I

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
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.