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

Percentage Column

Hi I am struggling with percentages in power bi - i have tried many combinations and none of them are correct. I have a table that I want to provide percentage of compliance in the % column: 

PRODUCTSpot Checks TotalsTotal_Compliant%
PRODUCT 1106 
PRODUCT 2240 
PRODUCT 322 
PRODUCT 41212 
PRODUCT 522 

 

Is there a good way to produce percentages in power bi for the above column please?

 

Thank you

2 ACCEPTED SOLUTIONS

As I indicated in my code comments, you only need to change the "Source=" line to reflect your actual data source.  What happened when you tried it?  M-code is M-code and can use multiple data sources.

 

Another option, in Power BI, would be to use a Measure (add a column). 

 

 

% = [Total_Compliant]/[Spot Checks Totals]

 

and, again, set the data type to percentage (here you'd use a dropdown in the Column Tools menu to set the cell format.

 

ronrsnfld_0-1665709589862.png

 

 

View solution in original post

Got it!

 

It was my fault. I've corrected it now. It reads:

 

% = ('Tiers 1 & 2 - Outcomes'[Spot Checks Compliant]/[Spot Checks Totals])

View solution in original post

11 REPLIES 11
ronrsnfld
Super User
Super User

Just divide Total_Compliant by Spot Checks Total

 

eg

let

//change next line to reflect actual data source.
    Source = Excel.CurrentWorkbook(){[Name="Compliance"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{
        {"PRODUCT", type text}, {"Spot Checks Totals", Int64.Type}, {"Total_Compliant", Int64.Type}}),

    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each [Total_Compliant]/[Spot Checks Totals], Percentage.Type)
in
    #"Added Custom"

 

Personal preference but, if I have a column showing a percentage, I prefer to leave it as such instead of multiplying by 100 

Original data

ronrsnfld_0-1665706538721.png

 

Results

ronrsnfld_1-1665706578677.png

 

 

I reread your feedback and I have tried to address this with the source in Power BI

macgeorge_0-1665709302623.png

 

The table in Power BI is called "Tiers 1 & 2 - Outcomes". The columns in that table are exactly as above.

Am I using a Measure to do this calculation? If so, can you please write this for me, as I am getting lost. Sorry.

Read my edited previous response which now provides a DAX solution.

 

My first response was M-Code which is in Power Query which you get to by selecting Transform Data from the Home tab of Power BI.

 

My second response includes a DAX solution which you enter using "New Column" from the Table Tools or Column Tools tab.

Thank you for this.

Would the code look any different if the source is in Power BI already, I may have mislead you that I am working from Excel. 

I provided the example from Excel to explain what output I need in Power BI.

Again, apologies, I am a novice here.

As I indicated in my code comments, you only need to change the "Source=" line to reflect your actual data source.  What happened when you tried it?  M-code is M-code and can use multiple data sources.

 

Another option, in Power BI, would be to use a Measure (add a column). 

 

 

% = [Total_Compliant]/[Spot Checks Totals]

 

and, again, set the data type to percentage (here you'd use a dropdown in the Column Tools menu to set the cell format.

 

ronrsnfld_0-1665709589862.png

 

 

Nearly there...I am getting a syntax error during parsing on this:

% = ('Tiers 1 & 2 - Outcomes)[Total_Compliant]/[Spot Checks Totals]

You probably need to remove the parentheses:

 

% = 'Tiers 1 & 2 - Outcomes[Total_Compliant]/[Spot Checks Totals]

 

but I don't think you need the table specification at all, since the column is in the same table as your data.

 

What happened when you used the formula as I provided it, without the table name?

 

I kept the table name in there as there are other tables. Excellent work. I was clearly over complicating things.Its working perfectly now thanks to your help, guidance and most of all patience. 

Got it!

 

It was my fault. I've corrected it now. It reads:

 

% = ('Tiers 1 & 2 - Outcomes'[Spot Checks Compliant]/[Spot Checks Totals])
macgeorge
Helper I
Helper I

The table I am working on looks likes this (in Excel):

macgeorge_1-1665699341316.png

 

In Excel the formulae is simple: =SUM(C2/B2*100)

I am trying to to wrack my brains (failing) to work out how to do this in DAX that will provide the percentage for each row. The percentage should show how many spot checks are compliant against the spot check done for that product.

 

Any help please would be gratefully appreciated. 

 

 

macgeorge
Helper I
Helper I

Just one thing - i am trying to do the % of each line for example product 1 has had 10 spot checks whereby 6 were compliant - the percentage for that would be 60% compliant

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.

Top Solution Authors
Top Kudoed Authors