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

Sales running total for specific years

I would like to compare a specific year's running total of sales by month to another year's running totals by month.

 

For example, the running total of 2021 compared to 2022, with month on the x-axis.

 

My data structured is shown in the abbreviated table below. Underneath the table is a sketch of what I would like the chart look like.

 

DateSales
1/2/2021500
2/1/2021400
6/20/2021700
1/2/2022400
3/1/2022600
4/1/2022300

 

DataScope06_0-1672677908451.png

 

1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

Hi @DataScope06 ,

 

You could create a calendar and then create a measure to calculate the running total.

Calendar = ADDCOLUMNS(CALENDAR(MIN('Table'[Date]),MAX('Table'[Date])),"Year",YEAR([Date]),"MonthNumber",MONTH([Date]),"Month",FORMAT([Date],"MMMM"))

Select the Month column and sort by the MonthNumber column.

vstephenmsft_0-1672910094028.png

The relationship is as follows.

vstephenmsft_1-1672910126909.png

Create the measure.

Running Total = CALCULATE(SUM('Table'[Sales]),FILTER(ALLSELECTED('Calendar'),[Year]=MAX('Calendar'[Year])&&[MonthNumber]<=MAX('Calendar'[MonthNumber])))

 

vstephenmsft_2-1672910153786.png

 

You can dowload my attachment for more details.

 

 

Best Regards,

Stephen Tao

 

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

7 REPLIES 7
v-stephen-msft
Community Support
Community Support

Hi @DataScope06 ,

 

You could create a calendar and then create a measure to calculate the running total.

Calendar = ADDCOLUMNS(CALENDAR(MIN('Table'[Date]),MAX('Table'[Date])),"Year",YEAR([Date]),"MonthNumber",MONTH([Date]),"Month",FORMAT([Date],"MMMM"))

Select the Month column and sort by the MonthNumber column.

vstephenmsft_0-1672910094028.png

The relationship is as follows.

vstephenmsft_1-1672910126909.png

Create the measure.

Running Total = CALCULATE(SUM('Table'[Sales]),FILTER(ALLSELECTED('Calendar'),[Year]=MAX('Calendar'[Year])&&[MonthNumber]<=MAX('Calendar'[MonthNumber])))

 

vstephenmsft_2-1672910153786.png

 

You can dowload my attachment for more details.

 

 

Best Regards,

Stephen Tao

 

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

This worked! Thank you. 

 

Also, part of my issues was due to discrepancy between fact and calendar table date formats. Specifically this was because my fact table date was in a datetime format. I found a blog post with details about the way this effects the relationship. Anyone having that issue can see the blog here: Relationship Issues With DateTime Data Types in Power BI — Havens Consulting

DataScope06
Helper I
Helper I

The thread linked below might have a solution posted by @amitchandak, however I am unable to download the workbook.

Solved: Running Total Chart over Multiple Years - Microsoft Power BI Community

Anonymous
Not applicable

For previous year:

CALCULATE(SUM(FactsTable[Sales]), SAMEPERIODLASTYEAR('Date'[DateKey]))

Then it's just a matter of using the sales column and applying a hidden filter so that it only shows data from the current year.

Thanks @Anonymous, what if I want to show running totals by specific year, rather than the previous year?

Anonymous
Not applicable

CALCULATE(
    SUM(Fatture[Importo Pagato]),
    DATEADD(
DATESINPERIOD(
'Date'[DateKey],
"yourDesiredStartDate",
nOfIntervals,
interval
),
nOfIntervals, //in multiples of 12 for months
MONTH/YEAR
)
)

 This should allow you to get any year you want.

You could also use FILTER(YEAR(DateKey)=yourDesiredYear).

I can't get your solution to work. Still searching for the solution to this issue.

 

Reminder the goal is to display the running total of sales for individual years on the same chart.

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.