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
aaronvincentnz
Helper III
Helper III

Calculate percentage from unpivoted data

Hello

 

Apologies if this has been asked before (I had a search but couldn't quite get the existing solutions to fit my query).

 

I have a column (let's call is Service Level) where the options are 'Good', 'Bad', 'N/A' and I have a column for Unique ID. I have unpivoted my original data set (to calculate a separate formula) so am now left with duplicate unique ID's and duplicate Service Level responses.

 

What formula do I need to use to calculate the % of 'Good', 'Bad', 'N/A' by unique ID given that the data is unpivoted?

 

Thanks in advance

1 ACCEPTED SOLUTION

Hi. Create a visualization with Service Level and a measure like this:

% of unique =
VAR _num = DISTINCTCOUNT(Table[Unique])
VAR _den = CALCULATE(
    DISTINCTCOUNT(Table[Unique])
    , ALL(Table)
)
RETURN
DIVIDE ( _num , _den )

After that you can format the measure with % symbol.

Hope that helps, 


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

View solution in original post

8 REPLIES 8
amitchandak
Super User
Super User

@aaronvincentnz ,Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Unique IDService Level
1054Good job
1054Good job
1054Good job
1054Good job
1054Good job
1054Good job
1054Good job
1074Bad job
1074Bad job
1074Bad job
1074Bad job
1074Bad job
1074Bad job
1156Don't know
1156Don't know
1156Don't know
1156Don't know
1156Don't know
1156Don't know
1156Don't know
1221Good job
1221Good job
1221Good job
1221Good job
1255Good job
1255Good job
1255Good job
1255Good job
1266Bad job
1266Bad job
1266Bad job
1266Bad job
1266Bad job
1266Bad job
1266Bad job

Hi. Create a visualization with Service Level and a measure like this:

% of unique =
VAR _num = DISTINCTCOUNT(Table[Unique])
VAR _den = CALCULATE(
    DISTINCTCOUNT(Table[Unique])
    , ALL(Table)
)
RETURN
DIVIDE ( _num , _den )

After that you can format the measure with % symbol.

Hope that helps, 


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

The formula works, but the result is incorrect - I know what the result is meant to be based on checking via a pivot table from the original source data....it looks like I'd get the same result if I use the % of grand total function within the Values field without using any sort of formula...

Hi @aaronvincentnz,

It seems like you share the duplicate sample data with the same status, can you please share some data with raw table structures and expected result to test?

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Here's a sample of the data (apologies for the messy formatting)

The 'don't know' is equivalent to N/A from the original info in my question

 

Data Unpivoted
Unique IDService Level
1054Good job
1054Good job
1054Good job
1074Bad job
1074Bad job
1074Bad job
1156Don't know
1156Don't know
1156Don't know
1221Good job
1221Good job
1221Good job
1221Good job
1255Good job
1266Bad job
1266Bad job

 

Original Data
Unique IDService Level
1054Good job
1074Bad job
1156Don't know
1221Good job
1255Good job
1266

Bad job

 

Expected Result  
Service LevelActual Counts% of Service Level
Good Job350%
Bad Job233%
Don't Know116%
Total6100%

Here is a measure expression that gets the result shown in a table visual with the Service Level column.  Replace Service with your actual table name.

 

% of Service Level =
VAR countsatlevel =
    DISTINCTCOUNT ( Service[Unique ID] )
VAR countsoverall =
    CALCULATE (
        DISTINCTCOUNT ( Service[Unique ID] ),
        ALL ( Service[Service Level] )
    )
RETURN
    DIVIDE (
        countsatlevel,
        countsoverall
    )

 

Regards,

Pat

 

 

 

mahoneypat_0-1604153092993.png

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


That's worked, thanks (sorry for the late reply, been on leave). Just have to work out how to make the legend not display in alphabetical order lol...

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.