To put two level of data in one tableau worksheet and aggregate them - aggregate

I'm building up a supervisor scorecard on Tableau. Basically, there're two parts impacted on supervisor's score. One is supervisor's own performance, eg. there own's lateness. And the other part was their reporting employees' performance, eg. their employees' absenteesim.
My expectation is aggregating all the criteria in dashbaord, and filter supervisor's ID get his scorecard data. Here is a sample of the raw data:
So from the data we can know that for each CSR, they all have their supervisor, and for a supervisor, their reporting supervisor(which should be a manager) is blank.
So I created 3 calculation filed. One is called SUP_ID, and here's the code:
IF ISNULL([SupervisorID]) THEN [EmployeeID]
ELSE [SupervisorID]
END
Another calculation filed is called SUP_Flag, the code is :
[EmployeeID]=[SupervisorID____OLD]
The last one called SupervisorID___OLD], the code is:
IF [ROLE] = 'Supervisor' THEN [EmployeeID]
ELSE NULL
END
With these three calculation field, i'm able to use SUP_ID to filter all the information I want in each worksheet. When I want each supervisor's belonging employee's performance, I'll just use SUP_ID as filter. If I want each supervisor's own performance, I use SUP_ID as well as SUP_Flag to give me the information, and it works very well.
Everything above was done by separate worksheet.
Now my problem is:
There's a field that i need to put is called supervisor's final score, and it combines with both employee's performance score and supervisor's own performance score together in one filed. These two score are both in previous seperate worksheet. I'm thinking to use LOD to aggregate them, but it doesn't work as my expectation.
Here's what i wrote:
Final_Score_Part1(Sup's performance)
{FIXED [SUP_ID],[Supe Flag]: ([EVALUATION SC]*1* 0.2)}
Final_Socre_Part2(Employee's performance)
{FIXED [SUP_ID],[Supe Flag]: ((([LOST TIME %] * 0.6) + ([ATTENDENCE_SC]*0.2) + ([PUNCTUALITY_SC]*0.2)) * 0.5 )}
Final_Score:
Final_Score_Part1 + Final_Socre_Part2
Here's the screenshot that Tableau gave me.
(I've crossed out Supervisor's name)
So you can see that the part1 score was based on Sup_Flag = True, and part2 socre is based on SUp_Flag = Null, so when i aggregate them, it still won't give me the correct score.
Can somebody help me with this? I'll be so apprecaited for your help.
Thanks
Hi #Phani,
As i couldn't upload an image in comment, i've posted the new image here
enter image description here

For Final_Score_Part1(Sup's performance): include the condition
IF [ROLE] = 'Supervisor' THEN calculate the score[]
ELSE NULL
END
The same condition need to be used in Final_Socre_Part2(Employee's performance).

Related

PowerBI - calculation with 2 different dates

I have one data table from which I have to calculate 2 different KPIs, each KPI is tied to different date column.
"Creation Date" for KPI "Net Satisfaction Score" calculation and "Uni Date" for KPI "Response Rate" calculation.
"Date" from "Date table" used as field to filter time periods so I need to have a relation to that field.
table design
If I filter for results in September'22, I want to see "Net Satisfaction Score" calculated from all Ids with Creation date in SEP'22, and I want to see "Response Rate" calculated from all Ids with UniDate in SEP'22 (this means Ids 00004, 00007, 00009 and 00010 are not to be considered in Response Rate calculation).
What I have tried already:
Using more queries - one for Response Rate (with relation UniDate <-> Date) and second one for Net Satisfaction Score (with relation Creation Date <-> Date).
This worked, but if I want to go more into detail and see the results by country, the numbers don't show up correctly, as there is no relation on "Country" or whatever detail I want to split the result by.
Making relation based on IDs between the queries mentioned in "1)" - circular dependency error.
I am really out of ideas, but maybe some of you tried to solve this kind of issue already.
Sounds like you need to use USERELATIONSHIP within your measure.
You will need something like this
Net Satisfaction Score = CALCULATE(Sum('Net Satisfaction Table[Score]'),
USERELATIONSHIP('DateTable[Day]','Net Satisfaction Score Table[Created Date]))
You can obviously use sum, count, average...whatever you need to do with your score. You also need to make sure that both dates - Created Date and UniDate have an inactive relationship back to your Date Table.
Repeat the same measure example for your other measure. USERELATIONSHIP works perfectly on inactive relationships and only works within CALCULATE operation where you tell PowerBI which date to use in this calculation.

Tableau KPI prev value depending on variable

am trying to get Previous Sum(of someField) based on a variable value which is an Id.
This is not a table, Im doing a KPI
On Qlik you would do something like:
SUM({<Id={"$(=Max(vVariable),-1))"}>} someField)
But I can not achieve it on Tableau, off course is due to my lack of knowledge, unfortunatelly time is tinking at work and wanted to see if anyone has any input!
Thanks
Assuming you may use a sample input like the Superstore (using sales as metric), this could be what you're looking for:
In red you can see your "variable" which allows you to select a value and in blue you'll find the unique row for the previous value (Order ID sorted).
The first thing you need to to do is creating a parameter based on all the Order ID values:
Then things start to get a bit complicated if you're not familiar with LOD (Level of details) and the order of execution in Tableau, especially for filters.
Assuming that you can get some information on your own (otherwise, feel free to ask), the first thing you nee to to do is to "pre-calculate" the equivalent of a table having a rowe for each Order ID, in which you also have the previous Order ID value.
You can achive this combining Fixed (LOD) and Lookup function, creating this Calculated Field "Lookup Order ID":
LOOKUP( max({ FIXED [Order ID] : MAX([Order ID])}),1)
This is actually just a calculated field that you want to "fix" because you need the filter to act after you have made that previous calculus, and then you shift your data by 1 row backward.
Once you've done that, you just nee to create another calculated field in order to test your parametric value, and it could be something like this "check param":
[Lookup Order ID] = [Order ID param]
Moving this calculated field in the filter section and selecting just "true" values, you'll get that unique rows like in the initial image, showing the previous value (blue) related to the one you select in the parameter drop-down menu (red).

Tableau Calculated Field to Display Specific Rows

I'm trying to find a way to display only certain rows of my data based off a very specific criteria. I will try to explain it the best way I can. Let's start with a screenshot here:
Picture of part of the Tableau sheet as-is
What I'm trying to do is create a way to display only the values of "Order: Sales Order #" that have a value filled in for "Item: Connected Product Category". As you see on the screenshot, order number 15589543 has one Connected Product Category that displays "Connectable".
Since this order number does not only have null field for the Connect Product Category, I would like ALL of the rows (even the blank ones) be displayed for order # 15589543. If an order # has NO rows that have "connectable" displayed in them (orders 10305573, 15573299, 15699578, etc.) I would like these orders to be filtered out.
This is a screenshot of just a small part of the data. Basically, if an order has a "connectable" field in it, I need all of the rows for that order # to be displayed.
I tried to do logic such as IF [Item: Connected Product Category] = "Connectable" THEN [Order: Sales Order #] ELSE NULL END but this only displays the rows that literally contain "connectable" in them, not all of the rows for that order number.
Any assistance would be greatly appreciated. After extensive research I'm not sure if this is even possible. Thanks
It is simple. Create a calculated field desired filter as
{FIXED [Order: Sales Order #] : SUM(
IF [Item: Connected Product Category] = 'Connectable' THEN 1 ELSE 0 END
)} > 0
This calculated field will evalaute as TRUE/FALSE and setting filter on this field for TRUE will filter records as desired.
Try this. Good luck

DAX: Distinct and then aggregate twice

I'm trying to create a Measure in Power BI using DAX that achieves the below.
The data set has four columns, Name, Month, Country and Value. I have duplicates so first I need to dedupe across all four columns, then group by Month and sum up the value. And then, I need to average across the Month to arrive at a single value. How would I achieve this in DAX?
I figured it out. Reply by #OscarLar was very close but nested SUMMARIZE causes problems because it cannot aggregate values calculated dynamically within the query itself (https://www.sqlbi.com/articles/nested-grouping-using-groupby-vs-summarize/).
I kept the inner SUMMARIZE from #OscarLar's answer changed the outer SUMMARIZE with a GROUPBY. Here's the code that worked.
AVERAGEX(GROUPBY(SUMMARIZE(Data, Data[Name], Data[Month], Data[Country], Data[Value]), Data[Month], "Month_Value", sumx(CURRENTGROUP(), Data[Value])), [Month_Value])
Not sure I completeley understood the question since you didn't provide example data or some DAX code you've already tried. Please do so next time.
I'm assuming parts of this can not (for reasons) be done using power query so that you have to use DAX. Then I think this will do what you described.
Create a temporary data table called Data_reduced in which duplicate rows have been removed.
Data_reduced =
SUMMARIZE(
'Data';
[Name];
[Month];
[Country];
[Value]
)
Then create the averaging measure like this
AveragePerMonth =
AVERAGEX(
SUMMARIZE(
'Data_reduced';
'Data_reduced'[Month];
"Sum_month"; SUM('Data_reduced'[Value])
);
[Sum_month]
)
Where Data is the name of the table.

Identifying next closest record by date in tableau

I have a table of users and another table of transactions.
The transactions all have a date against them. What I am trying to ascertain for each user is the average time between transactions.
User | Transaction Date
-----+-----------------
A | 2001-01-01
A | 2001-01-10
A | 2001-01-12
Consider the above transactions for user A. I am basically looking for the distance from one transaction to the next chronologically to determine the distances.
There are 9 days between transactions one and two; and there are 2 days between transactions three and four. The average of these is obviously 4.5, so I would want to identify the average time between user A's transactions to be 4.5 days.
Any idea of how to achieve this in Tableau?
I am trying to create a calculated field for each transaction to identify the date of the "next" transaction but I am struggling.
{ FIXED [user id] : MIN(IF [Transaction Date] > **this transaction date** THEN [Transaction Date]) }
I am not sure what to replace this transaction date with or whether this is the right approach at all.
Any advice would be greatly appreciated.
LODs dont have access to previous values directly, so you need to create a self join in your data connection. Follow below steps to achieve what you want.
Create a self join with your data with following criteria
Create an LOD calculation as below
{FIXED [User],[Transaction Date]:
MIN(DATEDIFF('day',[Transaction Date],[Transaction Date (Data1)]))
}
Build the View
PS: If you want to improve the performance, Custom SQL might be the way.
The only type of calculation that can take order sequence into account (e.g., when the value for a calculated field depends on the value of the immediately preceding row) is a table calc. You can't use an LOD calc for this kind of problem.
You'll need to understand how partitioning and addressing works with table calcs, along with specifying your sort order criteria. See the online help. You can then do something like, for example, define days_since_last_transaction as:
if first() > 0 then min([Transaction Date]) -
lookup(min([Transaction Date]), -1) end
If you have very large data or for other reasons want to do your calculations at the database instead of in Tableau by a table calc, then you use SQL windowing (aka analytical) queries instead via Tableau's custom SQL.
Please attach an example workbook and anything you tried along with the error you have.
This might not be useful if you cannot set User ID Field as a filter.
So, you can set
User ID
as a filter. Then following the steps mentioned in here will lead you to calculating difference between any two dates. Ideally if you select any one value in the filter, the calculated field from the link should give you the difference in the dates that you have in the transaction dates column.