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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
alihijazi
Helper I
Helper I

Margin % Calculation

Hello got the below table in which I'm displaying the sales by Engineer per year

margin(%) calculation.png

 

what I want now is to calculate per engineer per year the Margin(%) which is calculated as follows (pseudo code):

for 2010: (sales (2010) - sales(2009)) / sales(2009)

 

if the Sales measure is defined as follows:

Sales = CALCULATE(sum(Transactions[cSales]),Transactions[SDLNTY]="SA" || Transactions[SDLNTY]="RG" )

 

what would be the sales of previous year?

Please advise

8 REPLIES 8
Sean
Community Champion
Community Champion

@alihijazi 

 

PY Sales = CALCULATE ( [Sales], PREVIOUSYEAR(CalendarTable[Date])

 

YoY $ = [Sales] - [PY Sales]

 

YoY % = DIVIDE ( [YoY $], [PY Sales], 0)

Can I share with you the file I'm working on?

it didn't work for me the previous year sales; it is giving blanks

Sean
Community Champion
Community Champion

Do you have a Calendar Table?

 

If not visit @MattAllington's link - http://www.powerpivotpro.com/2015/02/create-a-custom-calendar-in-power-query/

 

Time Intelligence Functions require the presence of a Calendar Table

I created a calendar using first =List.Date and then converting the list to table and  I added the parts of the dates (year, month, week, quarter ...) 

but still it returns blank

Please advise

Sean
Community Champion
Community Champion

@alihijazi so you created a separate Calendar Table? Did you create a Relationship between the 2 tables?

 

Relate.png

indeed @Sean

Sean
Community Champion
Community Champion

@alihijazi  If you have the Calendar table set up as described in Matt's link I provided above - evertything should work

I tried to make my sample data as close as possible to your example and I'm including the formulas again

Everything should work okay - don't you get anything to work at all?

 

YoY Percent.png

 

Sean
Community Champion
Community Champion

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

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