Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. 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.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.
| User | Count |
|---|---|
| 48 | |
| 46 | |
| 41 | |
| 20 | |
| 17 |
| User | Count |
|---|---|
| 70 | |
| 69 | |
| 32 | |
| 27 | |
| 26 |