cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
OSLacour
Regular 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. 

 

YearTotal salesTotal sales 2018
20171000012500
20181250012500
20191400012500
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
guiborlenghi
Regular 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

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

 

View solution in original post

2 REPLIES 2
Highlighted
guiborlenghi
Regular 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

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

 

View solution in original post

OSLacour
Regular Visitor

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

Thank you very much. 

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Join THE global Microsoft Power Platform event series.

Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors