Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi,
I need to calculate the acumulative sales starting from a certain period (something similiar to Sales YTD
I used this:
Below is my mock up data.
Thanks,
Year | Quarter | Month | Sales | Acum Sales |
2013 | Qtr 4 | November | 6.350 | |
2013 | Qtr 4 | December | 60.000 | |
2014 | Qtr 1 | January | 50.000 | |
2014 | Qtr 1 | February | 70.000 | 6.350 |
2014 | Qtr 1 | March | 45.000 | 66.350 |
2014 | Qtr 2 | April | 25.000 | 116.350 |
2014 | Qtr 2 | May | 30.000 | 186.350 |
2014 | Qtr 2 | June | 45.000 | 231.350 |
2014 | Qtr 3 | July | 10.000 | 256.350 |
2014 | Qtr 3 | August | 50.000 | 286.350 |
391.350 |
Hi @clarainesgg, here is an algorithm:
Attached you can find an example for your specific case when there is only one flat table and your numbers are available at monthly level only. Read it in the following way:
Acum Sales =
VAR _RowNumberByYearMonthNumber = MIN( 'Table'[RowNumberByYearMonthNumber] ) //get current value of the column
VAR _Offset= 3 //when you want to start capturing previous data
VAR _CurrentOffset = _RowNumberByYearMonthNumber - _Offset //to check if you arrived to a necessary month
VAR _Result =
IF(
_CurrentOffset >= 0, //when we are at a necessary month or after
CALCULATE( //than calculate a sum
SUM( 'Table'[ Sales ] ),
ALL( 'Table' ), //necessary to remove filters from other columns such as year, month etc.
'Table'[RowNumberByYearMonthNumber] <= _CurrentOffset
),
BLANK() //otherwise keep it blank
)
RETURN _Result
Here is the final result:
In case you have a proper data model with Calendar table marked as "Date table" (Do You Need a Date Dimension? - RADACAD) and sales at daily granularity you can follow @rajendraongole1's suggestion and use date column for the ranking system.
Good luck with your project! 🙂
I got an error when i want to create a row_number
Hi @clarainesgg -can you check the below modified dax formaule
Cumulative Sales =
VAR CurrentDate = MAX('Calendar'[Date])
VAR FirstDateOfPreviousMonth = EDATE(CurrentDate, -1) // Shifts date back by one month
RETURN
CALCULATE(
SUM('financials'[Sales]),
FILTER(
ALL('Calendar'),
'Calendar'[Date] >= FirstDateOfPreviousMonth && 'Calendar'[Date] <= CurrentDate
)
)
I am assuming if the current context is March 2014, this DAX formula will accumulate sales starting from February 2014 and continue to accumulate as you move forward.Hope this works
Proud to be a Super User! | |
I need to start from february to bring my sales from nov-23 and so on.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
58 | |
56 | |
56 | |
38 | |
29 |
User | Count |
---|---|
75 | |
62 | |
45 | |
40 | |
39 |