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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
petrk
New Member

percentage calculation

Hi, please for help.
I have table like this, and I need calculate values in column "per of X", it is calculated by formula "per of X = value / X" where X is sum of all values which has in name "x". So X=5+4+3=12

At the report I have slicer for filtering dates. And I need to keep calculation according this filter. So use calculation for all visible values.  
Thank you for you ideas

 

datenamevalueper of X
01.03.2024  x1  5  42%
07.07.2024  x2  4  33%
07.09.2024  x3  3  25%
17.06.2024  y1  10  83%
25.06.2024  y2  8  67%
09.08.2024  u1  1  8%
11.09.2024  u2  5  42%
    
  X  12  
    

petrk_0-1728335925455.png

 

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

Hi @petrk ,

 

I've made a test for your reference:

1\ I assuem there is a table(Table)

vbofengmsft_0-1728616203089.png

2\Add a measure

Per of X = 
Var CurrentItemValue =Max('Table'[value])
Var CurrentItemName= LEFT(SELECTEDVALUE('Table'[name]),1)
Var SUMValue=CALCULATE(SUM('Table'[value]),FILTER(ALL('Table'),LEFT('Table'[name],1)=CurrentItemName))
RETURN
CurrentItemValue/SUMValue

3\Result

vbofengmsft_1-1728616241638.png

 

Best Regards,

Bof

 

View solution in original post

7 REPLIES 7
v-bofeng-msft
Community Support
Community Support

Hi @petrk ,

 

I've made a test for your reference:

1\ I assuem there is a table(Table)

vbofengmsft_0-1728616203089.png

2\Add a measure

Per of X = 
Var CurrentItemValue =Max('Table'[value])
Var CurrentItemName= LEFT(SELECTEDVALUE('Table'[name]),1)
Var SUMValue=CALCULATE(SUM('Table'[value]),FILTER(ALL('Table'),LEFT('Table'[name],1)=CurrentItemName))
RETURN
CurrentItemValue/SUMValue

3\Result

vbofengmsft_1-1728616241638.png

 

Best Regards,

Bof

 

collinq
Super User
Super User

Hi @petrk ,

 

You may have better results in the Dax section for Power BI but I will take a run at this.  I belive that this is two measures.  The first one is to calculate the summation based on the Name colum.  So, it will be like this:
SumValue = Calculate(Sum(Table[value]), Allexcept(Table, Table[name]))

 

Then, the second measure will be to determine what percentage is each individual row against that total:
% = DIVIDE(Table[Value], Table[TotalByName], 0)

 

Give that a try!




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

Proud to be a Datanaut!
Private message me for consulting or training needs.




Hi @collinq ,

thank you, but your solution doesn't work. I have attached pictures of report and your calculation. Wha I have wrong?   

petrk_0-1728365204985.png

 

petrk_1-1728365242657.png

 

@petrk 

Measure for Sum of X Values:

Total_X =
CALCULATE (
SUM(Table[value]),
FILTER (
Table,
LEFT(Table[name], 1) = "x" // Filters rows where name starts with 'x'
)
)

Per of X Measure:

Per_of_X =
DIVIDE (
Table[value],
[Total_X],
0 // To handle division by zero
)

 

If this helped, a Kudos 👍 or Solution mark would be great!
Cheers,
Kedar Pande
www.linkedin.com/in/kedar-pande

hi @Kedar_Pande ,
calculation of Total_X is OK but Per_of_X has issue. PBI doesn't allow me enter Table[value] to formula. It offer me to use just another measures which I have calcalated.

PBI error: A single value for column 'value' in table 'myTable' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

Do you have some idea how to solve it?

petrk_0-1728386015542.png

 

Updated Measure:

Per_of_X =
DIVIDE (
SelectedValue(Table[value]),
[Total_X],
0 // To handle division by zero
)

@Kedar_Pande
now formula works, but it returns value just for rows with x1, x2, x3. see picture

petrk_0-1728388470683.png

 

  

 
 

 

 

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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