cancel
Showing results for
Did you mean:
Frequent Visitor

## Calculate total last year in all rows in 1 column

Hello. I want to calculate for example the total amount of the sales from previous year and show this amount in the column 'total sales 2018'.

How can I do this? Thanks for a response.

 Year Total sales Total sales 2018 2017 10000 12500 2018 12500 12500 2019 14000 12500
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Visitor

## Re: Calculate total last year in all rows in 1 column

Hello!

To calculate the total from distinct periods, we need to use the functions of "time intelligence". For that, we need a "Calendar Table". So, here's what we gotta do:

1- Create a new column in the date format based on your Year;

`NewDate = DATE([Year];1;1)// This will generate a column with the dates "01/01/2017", "01/01/2018", "01/01/2019"`

2- Create a Calendar Table

Using the button "New Table", insert the DAX below:

`Calendar = // Will generate a table called "Calendar", starting on "01/01/2017" and finishing at "01/01/2019"CALENDAR(      MIN(Sales[NewDate]);      MAX(Sales[NewDate]) )`

3- Create a relationship between the "Sales" and "Calendar" tables using the columns Sales[NewDate] (many side) and Calendar[Date] (one side). In this case, the relationship will be "one to one", assuming that we have only one row for each Year in the Sales table.

4- Create the new metric for the total sales amount from previous year:

```Total Sales Previous Year =
CALCULATE(
[Total Sales];
PREVIOUSYEAR('Calendar'[Date])
)```

5- Enjoy

Result Using the "Total Sales Previous Year"

If that solved your issues, remember to mark this as the correct awnser.

And if that's not what you were looking for, let me know and I will do the best to help you again.

2 REPLIES 2
Highlighted
Visitor

## Re: Calculate total last year in all rows in 1 column

Hello!

To calculate the total from distinct periods, we need to use the functions of "time intelligence". For that, we need a "Calendar Table". So, here's what we gotta do:

1- Create a new column in the date format based on your Year;

`NewDate = DATE([Year];1;1)// This will generate a column with the dates "01/01/2017", "01/01/2018", "01/01/2019"`

2- Create a Calendar Table

Using the button "New Table", insert the DAX below:

`Calendar = // Will generate a table called "Calendar", starting on "01/01/2017" and finishing at "01/01/2019"CALENDAR(      MIN(Sales[NewDate]);      MAX(Sales[NewDate]) )`

3- Create a relationship between the "Sales" and "Calendar" tables using the columns Sales[NewDate] (many side) and Calendar[Date] (one side). In this case, the relationship will be "one to one", assuming that we have only one row for each Year in the Sales table.

4- Create the new metric for the total sales amount from previous year:

```Total Sales Previous Year =
CALCULATE(
[Total Sales];
PREVIOUSYEAR('Calendar'[Date])
)```

5- Enjoy

Result Using the "Total Sales Previous Year"

If that solved your issues, remember to mark this as the correct awnser.

And if that's not what you were looking for, let me know and I will do the best to help you again.

Frequent Visitor

## Re: Calculate total last year in all rows in 1 column

Thank you very much.

Announcements

#### Coming Soon: T-Shirt Design Contest

Keep your eyes open for our upcoming T-shirt design contest!

#### Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

#### Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

#### Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!