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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
RichOB
Helper I
Helper I

Turning numbers into percent's with calculations

Hi, I need help with some calculations for a survey.

 

In the example below the survey consists of 3 questions that are always in number form, “I Am Happy, I am Sad, I Am Neither”. The most 1 person can score per question is always 5 which means the total possible survey score is always 15. I need help with calculations to change them into percentages. The Total by City doesn't have a fixed number to calculate against (like 15 above) as it always changes due to the number of people within the city varying. 

 

1 – Total by City. How can I turn the numbers into % based on the amount of people who took the survey:

  • For example, 5 people from Newcastle took the survey so the total possible score is 75. They scored 66….66 / 75 x 100 = Newcastle average total score is 86.7%

 

2 – Total By Question – How can I get the % based on the score per question:

  • For example, Newcastle scored 21 out of 25 for “ I Am Happy “ = all people in Newcastle who picked I Am Happy is 84%

 

3 – Total By Person - For example, if Person 1 scored 13 out of 15, their score is 86.6%

 

I hope this makes sense, happy to give more information and thanks in advance.

 

PersonCompletion timeI Am HappyI Am Sad I Am NeitherArea CityPet 
103/01/2024445North NewcastleDog
211/01/2024555North NewcastleDog
325/01/2024334North NewcastleDog
429/01/2024445North NewcastleCat
501/02/2024555North NewcastleCat

 

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

Hi @RichOB ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create measures. 

Total By city = 
var _a=CALCULATE(DISTINCTCOUNT('Table'[Person]),FILTER(ALLSELECTED('Table'),'Table'[City]=MAX('Table'[City])))
var _b=_a*15
var _c=CALCULATE(SUM('Table'[Value]),FILTER(ALLSELECTED('Table'),'Table'[City]=MAX('Table'[City])))
RETURN DIVIDE(_c,_b,0)
Total By Question = 
var _a=CALCULATE(DISTINCTCOUNT('Table'[Person]),FILTER(ALLSELECTED('Table'),'Table'[City]=MAX('Table'[City])))
var _b=_a*5
var _c=CALCULATE(SUM('Table'[Value]),FILTER(ALLSELECTED('Table'),'Table'[City]=MAX('Table'[City]) && 'Table'[Attribute]=MAX('Table'[Attribute])))
RETURN DIVIDE(_c,_b,0)
Total By Person = 
var _a=CALCULATE(SUM('Table'[Value]),FILTER(ALLSELECTED('Table'),'Table'[Person]=MAX('Table'[Person])))
var _b=15
RETURN DIVIDE(_a,_b,0)

(3) Then the result is as follows.

vtangjiemsft_0-1715323162539.png

Best Regards,

Neeko Tang

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

View solution in original post

1 REPLY 1
v-tangjie-msft
Community Support
Community Support

Hi @RichOB ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create measures. 

Total By city = 
var _a=CALCULATE(DISTINCTCOUNT('Table'[Person]),FILTER(ALLSELECTED('Table'),'Table'[City]=MAX('Table'[City])))
var _b=_a*15
var _c=CALCULATE(SUM('Table'[Value]),FILTER(ALLSELECTED('Table'),'Table'[City]=MAX('Table'[City])))
RETURN DIVIDE(_c,_b,0)
Total By Question = 
var _a=CALCULATE(DISTINCTCOUNT('Table'[Person]),FILTER(ALLSELECTED('Table'),'Table'[City]=MAX('Table'[City])))
var _b=_a*5
var _c=CALCULATE(SUM('Table'[Value]),FILTER(ALLSELECTED('Table'),'Table'[City]=MAX('Table'[City]) && 'Table'[Attribute]=MAX('Table'[Attribute])))
RETURN DIVIDE(_c,_b,0)
Total By Person = 
var _a=CALCULATE(SUM('Table'[Value]),FILTER(ALLSELECTED('Table'),'Table'[Person]=MAX('Table'[Person])))
var _b=15
RETURN DIVIDE(_a,_b,0)

(3) Then the result is as follows.

vtangjiemsft_0-1715323162539.png

Best Regards,

Neeko Tang

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

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.