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
o59393
Post Prodigy
Post Prodigy

Assign a value to a letter to calculate a KPI

Hi all

 

I have assigned a value to a letter creating a table like this:

 

SGP  Value

C10
NA 
O5
R0

 

In case of the NA, should not be considered for the KPI.

 

The KPI desired is simple:

 

C= (Total count of C * 10) / 
(Total count of C * 10) + (Total count of O * 5) + (Total count of R * 0)

 

O= (Total count of O * 5) / 
(Total count of C * 10) + (Total count of O * 5) + (Total count of R * 0)

 

R= (Total count of R * 0) / 
(Total count of C * 10) + (Total count of O * 5) + (Total count of R * 0)

 

total KPI = (Total count of C * 10) + (Total count of O * 5 + (Total count of R * 0) 
/ 
(Total count of C * 10) + (Total count of O * 10) + (Total count of R * 10)

 

My dax is traduced into this (apologies if is not an efficient formula):

SGP KPI = 

var C = 

CALCULATE(COUNTROWS(Sheet3),Sheet3[SGP]="C")*CALCULATE(SUM('Value'[Value]),'Value'[SGP]="C") / 

( CALCULATE(COUNTROWS(Sheet3),Sheet3[SGP]="C")*CALCULATE(SUM('Value'[Value]),'Value'[SGP]="C") + 
CALCULATE(COUNTROWS(Sheet3),Sheet3[SGP]="O")*CALCULATE(SUM('Value'[Value]),'Value'[SGP]="O") + 
CALCULATE(COUNTROWS(Sheet3),Sheet3[SGP]="R")*CALCULATE(SUM('Value'[Value]),'Value'[SGP]="R") )


var O = 

CALCULATE(COUNTROWS(Sheet3),Sheet3[SGP]="O")*CALCULATE(SUM('Value'[Value]),'Value'[SGP]="O") / 

( CALCULATE(COUNTROWS(Sheet3),Sheet3[SGP]="C")*CALCULATE(SUM('Value'[Value]),'Value'[SGP]="C") + 
CALCULATE(COUNTROWS(Sheet3),Sheet3[SGP]="O")*CALCULATE(SUM('Value'[Value]),'Value'[SGP]="O") + 
CALCULATE(COUNTROWS(Sheet3),Sheet3[SGP]="R")*CALCULATE(SUM('Value'[Value]),'Value'[SGP]="R") )


var R = 

CALCULATE(COUNTROWS(Sheet3),Sheet3[SGP]="R")*CALCULATE(SUM('Value'[Value]),'Value'[SGP]="R") / 

( CALCULATE(COUNTROWS(Sheet3),Sheet3[SGP]="C")*CALCULATE(SUM('Value'[Value]),'Value'[SGP]="C") + 
CALCULATE(COUNTROWS(Sheet3),Sheet3[SGP]="O")*CALCULATE(SUM('Value'[Value]),'Value'[SGP]="O") + 
CALCULATE(COUNTROWS(Sheet3),Sheet3[SGP]="R")*CALCULATE(SUM('Value'[Value]),'Value'[SGP]="R") )


var total_KPI = 

(
CALCULATE(COUNTROWS(Sheet3),Sheet3[SGP]="C")*CALCULATE(SUM('Value'[Value]),'Value'[SGP]="C") + CALCULATE(COUNTROWS(Sheet3),Sheet3[SGP]="O")*CALCULATE(SUM('Value'[Value]),'Value'[SGP]="O") + CALCULATE(COUNTROWS(Sheet3),Sheet3[SGP]="R")*CALCULATE(SUM('Value'[Value]),'Value'[SGP]="R") 
)
/ 

( CALCULATE(COUNTROWS(Sheet3),Sheet3[SGP]="C")*CALCULATE(SUM('Value'[Value]),'Value'[SGP]="C") + 
CALCULATE(COUNTROWS(Sheet3),Sheet3[SGP]="O")*CALCULATE(SUM('Value'[Value]),'Value'[SGP]="C") + 
CALCULATE(COUNTROWS(Sheet3),Sheet3[SGP]="R")*CALCULATE(SUM('Value'[Value]),'Value'[SGP]="C") )

return 

total_KPI

 

The 2 problems I have are the following,

 

The dax is returning to NA a value and I want it to be blank. The second problem is that I dont know how to return the respective value of C, R, O, NA and total KPI value for each letter in the table below:

 

sgp total.PNG

 

Can you please tell me how to get it right?

 

I attach excel with datasource and sheet "Result desired" explains the calcualtion with the result.

 

Also attach pbix.

 

https://1drv.ms/u/s!ApgeWwGTKtFdhl1dea00ulywwf4b?e=ZhRah3

 

Thanks!

 

1 ACCEPTED SOLUTION

Hi @o59393

 

As I didnt add a default value for KPI,you can add "total" value as a default value,just modify the dax expression as below:

 

KPI = 
var _total=CALCULATE(SUM('Table (2)'[Count of value])*10,FILTER('Table (2)','Table (2)'[Row labels]="C"))+CALCULATE(SUM('Table (2)'[Count of value])*5,FILTER('Table (2)','Table (2)'[Row labels]="O"))+CALCULATE(SUM('Table (2)'[Total])*0,FILTER('Table (2)','Table (2)'[Row labels]="R"))
VAR C_percent= DIVIDE(CALCULATE(SUM('Table (2)'[Count of value])*10,FILTER('Table (2)','Table (2)'[Row labels]="C")),_total)
var O_percent=DIVIDE(CALCULATE(SUM('Table (2)'[Count of value])*5,FILTER('Table (2)','Table (2)'[Row labels]="O")),_total)
var R_percent=DIVIDE(CALCULATE(SUM('Table (2)'[Count of value])*0,FILTER('Table (2)','Table (2)'[Row labels]="R")),_total)
var _subtotal=CALCULATE(SUM('Table (2)'[Count of value])*10,FILTER('Table (2)','Table (2)'[Row labels]="C"))+CALCULATE(SUM('Table (2)'[Count of value])*10,FILTER('Table (2)','Table (2)'[Row labels]="O"))+CALCULATE(SUM('Table (2)'[Count of value])*10,FILTER('Table (2)','Table (2)'[Row labels]="R"))
var total_percent=DIVIDE(_total,_subtotal)
Return
SWITCH('Table (2)'[Row labels],"C",FORMAT(C_percent,"percent"),"O",FORMAT(O_percent,"percent"),"R",FORMAT(R_percent,"percent"),"Total",FORMAT(total_percent,"percent"),FORMAT(total_percent,"percent"))

 

 

And you will see:

 

Annotation 2020-04-22 095217.png

 

For the updated .pbix file,pls click here.

 

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

View solution in original post

10 REPLIES 10

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.