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
diogoricciardi
Frequent Visitor

Running Total for the same month of last year

Hey guys,

 

I have a Sales table that has the sales amount of a company since Jan/2018.

I'm building a line chart where I want to show three lines with the following running totals:
- Month (August/20)

- Month -1 (July/20)
- Month in Year -1 (August/19)

 

To calculate the running total in the current month I used :

 

CALCULATE([Sales Amount],
                   FILTER(
                              ALLSELECTED(Sales_Table),
                                                    Sales_Table[Sales_Date] <= MAX(Sales_Table[Sales_Date])
                    ),
                              MONTH(Sales_Table[Sales_Date]) = MONTH(TODAY()),
                              YEAR(Sales_Table[Sales_Date]) = YEAR(TODAY())
)

 

And it worked perfectly.

 

Now, for the other periods, I've already tried this in a lot of different ways, always getting the same results, sometimes a flat line with the total amount of the respective month (when using all selected), other times daily sales amount but not accumulated ( when not using allselected).

 

Can you guys give me a light of how I can do this?

 

Thanks in advance,

 

Diogo

 

 

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@diogoricciardi 

If you need to have the three measures as you need, first create a calendar table and link it to the sales table, add the measures as given in the attached file.

You can download the file: HERE



Fowmy_0-1597587887655.png

________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube, LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

5 REPLIES 5
Fowmy
Super User
Super User

@diogoricciardi 

If you need to have the three measures as you need, first create a calendar table and link it to the sales table, add the measures as given in the attached file.

You can download the file: HERE



Fowmy_0-1597587887655.png

________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube, LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Hey @Fowmy ,

 

Thank you very much for your reply.

I had managed to do it by creating a column in the sales table where the max date was the last day of the month I wanted to get but your solution is far more ellegant.

 

Thanks for the lesson.

 

Cheers

harshnathani
Community Champion
Community Champion

Hi @diogoricciardi ,

 

 

You need to have a date calendar and mark it as the date in model view.
Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

 

 

and you can use these for MTD Calculation

 

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last year MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-12,MONTH)))
last to last year MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-2,Year)))
last year MTD (complete) Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-12,MONTH))))
Month behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Month))
Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last MTD (complete) Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-1,MONTH))))

 

Regards,

Harsh Nathani

 

Hi harshnathani,

 

Thank you for your reply.

 

I'm sorry, I think I wasn't very clear.

What I mean by running total is that it accumulates given a certain period, let me give you an example:

 

DaySales AmountRunning Total (What I need)
11010
21020
31030

 

I'm having trouble calculating the running totals for periods last month and same period of last year.

Hi @diogoricciardi ,

 

You can use this measure

 

 

Measure =
CALCULATE (
    SUM ( Table[Sales amount] ),
    FILTER (
        ALL ( Table ),
        Table[Day]
            <= MIN ( Table[Num] )
    )
)

 

 

https://www.daxpatterns.com/cumulative-total/

 

https://community.powerbi.com/t5/Desktop/Calculating-running-total-based-on-month/td-p/426337

 

Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

 

 

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.