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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
vsteinbahs
Helper I
Helper I

How to create a calculated column for monthly sales difference per sales person

Hi,

I'm trying to add a calculated column to show the sales amount difference between current month and previous month per sales person, as shown in the attached screen pic.  Any help is greatly appreciated.

 

valuediff calculated column syntax.jpg

1 ACCEPTED SOLUTION

Hi @vsteinbahs ,

 

1.jpg

 

 

 

Column = 
var prevDate = CALCULATE(MAX('Table'[Date]), FILTER ('Table','Table'[SalesPerson] = EARLIER('Table'[SalesPerson]) && 'Table'[Date] < EARLIER('Table'[Date])))

var prevamount = CALCULATE(MAX('Table'[Amount]), FILTER('Table','Table'[SalesPerson] = EARLIER('Table'[SalesPerson]) && 'Table'[Date]  = prevDate))
RETURN

IF (prevamount = BLANK(), BLANK(),
'Table'[Amount] - prevamount)

 

 



https://community.powerbi.com/t5/Community-Blog/Getting-Previous-Values-in-Power-BI-Part-1/ba-p/1143...


Regards,

Harsh Nathani


Appreciate with a Kudos!! (Click the Thumbs Up Button)

Did I answer your question? Mark my post as a solution!

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@vsteinbahs , Try like

[Amount] -sumx(filter(table, [salesperson] =earlier([salesperson]) && eomonth([date],0) =eomonth(earlier([Date]),0)),[Amount])

Hi @amitchandak 

Thank you for such quick reply.  I tried to apply the command you proposed, but it doesn't seem to work, as shown in pic below.  Here is the link to actual pbix file.  Any ideas how to fix?

 

valuediff calculated column syntax_p2.jpg

Hi @vsteinbahs ,

 

1.jpg

 

 

 

Column = 
var prevDate = CALCULATE(MAX('Table'[Date]), FILTER ('Table','Table'[SalesPerson] = EARLIER('Table'[SalesPerson]) && 'Table'[Date] < EARLIER('Table'[Date])))

var prevamount = CALCULATE(MAX('Table'[Amount]), FILTER('Table','Table'[SalesPerson] = EARLIER('Table'[SalesPerson]) && 'Table'[Date]  = prevDate))
RETURN

IF (prevamount = BLANK(), BLANK(),
'Table'[Amount] - prevamount)

 

 



https://community.powerbi.com/t5/Community-Blog/Getting-Previous-Values-in-Power-BI-Part-1/ba-p/1143...


Regards,

Harsh Nathani


Appreciate with a Kudos!! (Click the Thumbs Up Button)

Did I answer your question? Mark my post as a solution!

Hi @harshnathani 

Thank you very much for such a quick response and solution!  I've tested it on few data tables, and it does work as expected.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.