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
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
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.