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
gingerclaire
Helper III
Helper III

Calculated column to SUM last 12 months of sales BY ACCOUNT number

I have data that looks like the below:

 

DateProductAccount numberValue
1 april 2024Product 11£5
1 april 2024Product 12£5
1 april 2024Product 21£5
1 april 2024Product 31£5

 

  • I need to add a calculated column to sum all sales in the last 12 months BY account number.
    My sales data is often a month old - so I need the calculation to be based on the 12 months before the most recent  date in the table
  • So I want it to look like the below.....as a column in my data table and not in a visual
DateProductAccount numberValueSales in last 12 months
1 april 2024Product 11£5 
1 april 2024Product 12£5 
1 april 2024Product 21£5 
1 april 2024Product 31£5 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @gingerclaire ,

When you choose to create a Calculated column, it enables it to be a column in your datasheet rather than in the view.

I also created a table similar to yours, but for the convenience of the DAX code, I chose to convert £5 to 5. If you want the original format, you can use the FORMAT function.

vyilongmsft_0-1726540497545.png

Then I think you can create a calculated column as suparnababu8 mentioned.

 

Column = 
VAR LatestDate = MAX('Table'[Date])
VAR StartDate = EDATE(LatestDate, -12)
RETURN
CALCULATE(
    SUM('Table'[Value]),
    FILTER(
        'Table',
        'Table'[Account number] = EARLIER('Table'[Account number]) &&
        'Table'[Date] >= StartDate &&
        'Table'[Date] <= LatestDate
    )
)

 

vyilongmsft_1-1726540581873.png

 

 

 

Best Regards

Yilong Zhou

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
suparnababu8
Super User
Super User

Hi @gingerclaire 

 

You need to create a calculate columns as mentioned below.'

SalesLast12Months = 
VAR CurrentDate = 'Table'[Date]
VAR AccountNumber = 'Table'[Account number]
VAR Last12Months = 
    CALCULATE(SUM('Table'[Value]),
        FILTER(
            'Table',
            'Table'[Account number] = AccountNumber &&
            'Table'[Date] <= CurrentDate &&
            'Table'[Date] > EDATE(CurrentDate, -12)
        )
    )
RETURN Last12Months

 

The use this calculated columns in your matrix/table chart.

 

If you need additional info pls follow the below URLs

 

https://community.fabric.microsoft.com/t5/Desktop/DAX-Calculate-sum-of-last-12-months-from-each-mont...

https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-Accumulative-Sum-of-Sales-...

https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/12-Previous-Months-Sum-for-each-mont...

 

Hope this helps you!

 

Thanks!

Kishore_KVN
Super User
Super User

Hello @gingerclaire ,

Please follow below steps to achieve your requirement.

step1: Please create a calendar table

step2: Create relationship between your calendar table date and sales table date columns

step3: Create a new measure with below DAX:

Total Sales Last 12 Months = 
CALCULATE(
    SUM(TableName[Value]),
    DATESINPERIOD(
        'Calendar'[Date],
        MAX('Calendar'[Date]),
        -12,
        MONTH
    )
)

Step4: Drag your measure into the table visual to get the required output. 

 

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

Hi - I want to have this as a column in my data table and not in a visual. Will this work too?

Anonymous
Not applicable

Hi @gingerclaire ,

When you choose to create a Calculated column, it enables it to be a column in your datasheet rather than in the view.

I also created a table similar to yours, but for the convenience of the DAX code, I chose to convert £5 to 5. If you want the original format, you can use the FORMAT function.

vyilongmsft_0-1726540497545.png

Then I think you can create a calculated column as suparnababu8 mentioned.

 

Column = 
VAR LatestDate = MAX('Table'[Date])
VAR StartDate = EDATE(LatestDate, -12)
RETURN
CALCULATE(
    SUM('Table'[Value]),
    FILTER(
        'Table',
        'Table'[Account number] = EARLIER('Table'[Account number]) &&
        'Table'[Date] >= StartDate &&
        'Table'[Date] <= LatestDate
    )
)

 

vyilongmsft_1-1726540581873.png

 

 

 

Best Regards

Yilong Zhou

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

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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