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
romilv1
Helper I
Helper I

Get Percentage values using formula in YTD column

Hi Guys,

Below is the matrix in Power BI. As you can see it brings Total Revenue & Gross Profit from database. We want to calculate Gross Profit %.

Formula is GP % (cell B4) = Total Revenue (B2) / Gross profit (B3)

The amount column is YTD column and the formula should preserve when user selects 12 months of data (amount in YTD)

 

hence for 12 months daata (row 8-11) also calculates GP% as given.

romilv1_0-1713461789458.png

 

My Question is how to calcuate GP %?

 

2 REPLIES 2
v-zhouwen-msft
Community Support
Community Support

Hi @ryan_mayu ,thanks for the quick reply, I'll add further.

Hi @romilv1 ,

I've assumed some data.

vzhouwenmsft_0-1713776415044.png

Please follow these steps:
1. Use the following DAX expression to create a column

Amount(In YTD) = 
IF('Table'[Col-1] = "Gross Profit",[Amount],SUMX(FILTER('Table','Table'[Col-1] = "Total Revenue" && 'Table'[Year] = EARLIER('Table'[Year]) && 'Table'[Month] <= EARLIER('Table'[Month])),'Table'[Amount]))

2.Use the following DAX expression to create a column

GP % = IF([Col-1] = "Total Revenue",BLANK(), 
DIVIDE(MAXX(FILTER('Table','Table'[Year] = EARLIER('Table'[Year]) && 'Table'[Month] = EARLIER('Table'[Month]) && 'Table'[Col-1] = "Gross Profit"),'Table'[Amount]),
MAXX(FILTER('Table','Table'[Year] = EARLIER('Table'[Year]) && 'Table'[Month] = EARLIER('Table'[Month]) && 'Table'[Col-1] = "Total Revenue"),'Table'[Amount(In YTD)])
))

3.Final output

vzhouwenmsft_1-1713776556879.png

 

ryan_mayu
Super User
Super User

could you pls provide some sample data?





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

Proud to be a Super User!




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.