简体   繁体   中英

Tableau - how do we calculate ratio of one dimension member to others?

I'm looking to compute the ratio of one dimension member with others. My dataset looks something like this,

Name Role       City Country
ABC  Admin      XYZ  PQR
DEF  Marketing  ZZZ  YYY
GHI  Admin      PPP  RRR

Assuming I create a Parameter with the list of roles, If I select Marketing, I need show there are 2 Admin people for every Marketing person in the company.

I think you want to show the ratio of roles dynamically, as per user selection. The data provided was very less, therefore, I have used the following sample data-

Name    Role
abc admin
def admin
gf  manager
asdf    manager
asdfg   manager
jhjh    assistant
ut  assistant
ii  assistant
eqw clerk
fvvf    clerk
egrthh  clerk
svfvf   clerk
etgw    MTS

Now proceed as follows- Step-1 right click Role field and create a parameter. Based on all values it has, a parameter will be created automatically eg Role Parameter .

Step-2 Create a calculated field desired ratio with the following calculation

{FIXED [Role]: COUNT([Name])}/
{MIN(IF 
[Role]=[Role Parameter]
then {FIXED [Role]: COUNT([Name])}
END)}

Step-3 create one more calculation field (optional) with the following calculation

[Role]=[Role Parameter]

Step-4: Build your View drag Sum(Desired Ratio) to columns shelf and text marks card, Role to rows shelf , optional field to color marks card; you'll get a desired view like this-

在此处输入图像描述

Whenever you'll select a role from role paramter the view will update

在此处输入图像描述

A little tweak in text and tooltip can give you a nice dashboard like this

在此处输入图像描述

I think this should solve your problem. Good luck

Here is one way, takes advantage of the fact that the type conversion function Int() converts True to 1 and false to 0

SUM(INT([Role]=“Admin”)) / SUM(INT([Role]=“Marketing”))

Alternatively, you could just make a table showing the Count of records for each role, and then use a quick table calc to compute percentages of the total.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM