Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Subtract Previous Date Sales from Current Date Sales and show result in a new column

So I have been working on the mentioned subject for past 10 hours straight and I give up. Need your help guys.

I have a table which has data as first table below.

 

I want a column that subtracts the Current date total sales for each member from previous date and shows the result as 'Today's Sale' for that member. 

 

 

DateSales ManTotal Sales
04/01/2020A2
04/01/2020B4
04/01/2020C6
04/02/2020A5
04/03/2020B6
04/03/2020C10

 

DateSales ManTotal SalesToday's Sale
04/01/2020A22
04/01/2020B44
04/01/2020C66
04/02/2020A53
04/03/2020B62
04/03/2020C104
1 ACCEPTED SOLUTION
v-kelly-msft
Community Support
Community Support

Hi @Anonymous ,

 

1.Go to query editor> add column> add index column;

2.Create a calculated column to rank the sales man column grouped by sales man:

 

 

Column = 
RANKX(FILTER('Table','Table'[Sales Man]=EARLIER('Table'[Sales Man])),'Table'[Index],,ASC,Dense)

 

 

3.Create a measure as below:

 

 

Measure = 
var a=CALCULATE(MAX('Table'[Total Sales]),FILTER(ALLSELECTED('Table'),'Table'[Column]=SELECTEDVALUE('Table'[Column])-1&&'Table'[Sales Man]=SELECTEDVALUE('Table'[Sales Man])))+0
Return
MAX('Table'[Total Sales])-a

 

 

Finally you will see:

Annotation 2020-04-16 122729.png

For the related .pbix file,pls click here.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

 

View solution in original post

3 REPLIES 3
v-kelly-msft
Community Support
Community Support

Hi @Anonymous ,

 

1.Go to query editor> add column> add index column;

2.Create a calculated column to rank the sales man column grouped by sales man:

 

 

Column = 
RANKX(FILTER('Table','Table'[Sales Man]=EARLIER('Table'[Sales Man])),'Table'[Index],,ASC,Dense)

 

 

3.Create a measure as below:

 

 

Measure = 
var a=CALCULATE(MAX('Table'[Total Sales]),FILTER(ALLSELECTED('Table'),'Table'[Column]=SELECTEDVALUE('Table'[Column])-1&&'Table'[Sales Man]=SELECTEDVALUE('Table'[Sales Man])))+0
Return
MAX('Table'[Total Sales])-a

 

 

Finally you will see:

Annotation 2020-04-16 122729.png

For the related .pbix file,pls click here.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

 

amitchandak
Super User
Super User

@Anonymous , The above solution from @parry2k will work. You can also try trailing day measure

Diff = SUM ( Table[Sales] ) -CALCULATE (SUM(Table[Sales]), dateadd('Date'[Date],-1,day ))

 

As mentioned by Parry, To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. 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/

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
parry2k
Super User
Super User

@Anonymous try following measure, key here is to add a calendar dimension in your model, set relationship with your sales table with this dimension and mark this dimension as date table. This will make any time intelligence calculation super easy and it is also a best practice.

 

Prev Day Sales Diff = 
SUM ( TableSales[Total Sales] ) - 
CALCULATE ( SUM ( TableSales[Total Sales] ), PREVIOUSDAY( 'Calendar'[Date] ) ) 

 

Would appreciate Kudos 🙂 if my solution helped.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.