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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
gcam032
Helper I
Helper I

Calculate within group % over xaxis

Hi All,

 

Haven't found the exact answer in the forums that seems to work for what I need.

I have a chart (see image) where the xaxis is a categorical variable (0, 100, 200, 300, 400.... 1000) groups.

My value is a sum.

I then have a Legend of YearMonth from a Date Dim table.

 

What I need is to display a %.  Each YearMonth % should add to 100% distributed across the categorical values.  In other words, a distribution density for each YearMonth.  So the raw figures below will be normalised as a density and displayed as %.

 

Screenshot 2020-03-30 at 16.44.27.png

1 ACCEPTED SOLUTION
v-kelly-msft
Community Support
Community Support

Hi @gcam032

 

1.Create a dim table:

 

 

 

dimdate = ADDCOLUMNS(CALENDARAUTO(),"YEARMONTH",YEAR([Date])*100+MONTH([Date]))

 

 

 

2.Create a measure:

 

 

 

Measure = CALCULATE(SUM('Table'[value])) / CALCULATE(SUM('Table'[value]),ALLEXCEPT('Table','Table'[Category]))

 

 

 

Finally you will see:

 

Annotation 2020-03-31 152128.png

 

For the related .pbxi file,pls click here.

 

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

 

 

View solution in original post

5 REPLIES 5
v-kelly-msft
Community Support
Community Support

Hi @gcam032

 

1.Create a dim table:

 

 

 

dimdate = ADDCOLUMNS(CALENDARAUTO(),"YEARMONTH",YEAR([Date])*100+MONTH([Date]))

 

 

 

2.Create a measure:

 

 

 

Measure = CALCULATE(SUM('Table'[value])) / CALCULATE(SUM('Table'[value]),ALLEXCEPT('Table','Table'[Category]))

 

 

 

Finally you will see:

 

Annotation 2020-03-31 152128.png

 

For the related .pbxi file,pls click here.

 

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

 

 

Hi Kelly,

 

Thanks for providing your solution.  It's close, but I need a slightly different calculation - can you help?

 

In your example, considering the Purple one, the percentages should be:

11% (11)

56% (56)

34% (34)

Sum to 100%

 

Pink would be:

13% (8)

53% (34)

34% (22)

Sum to 100%

 

Does that make sense?  It's within-group densities, where a group = YEARMONTH

 

After some trial and error- I figured out that I had to include the other filters I had applied to the chart.  Your solution was spot on!  Thank you!

Hi,

Share the link from where i can download your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Greg_Deckler
Super User
Super User

Divide by 100? Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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