I am building a report in Tableau with 4 fields. 3 of these fields are measure fields. This is what it looks like.
Name Sum Profit Loss
Emmy 15 10 5
Sara 23 18 2
Dave 10 1 2
But, I want it to look like this. I want a new column called metrics that pulls in those 3 values.
Metrics
Emily 15
10
5
Sara 23
18
2
Dave 10
1
2
May I have some guidance on how I can approach this?
The easiest way to solve this is by bringing "Measure Names" to Rows
You can hide the header names of the measures as well. hope that helps
I have a SQL table which has two columns called seq and sub_seq as seen below. I would like to add a third column called id, which goes up by 1 every time the sub_seq starts again at 1 as shown in the table below.
seq
sub_seq
id
1
1
1
2
2
1
3
3
1
4
4
1
5
5
1
6
1
2
7
2
2
8
3
2
9
1
3
10
2
3
11
3
3
12
4
3
13
5
3
14
6
3
15
7
3
I could write a solution using plpgsql, however I would like to know if there is a way of doing this in standard SQL. Any help would be greatly appreciated.
If sub_seq is always a running sequence then you can use the DENSE RANK function and order over the differences of two columns, assuming it will consistently uniform.
SELECT seq, sub_Seq, DENSE_RANK() OVER (ORDER BY seq-sub_Seq) AS id
FROM tableDemo
This solution is based on the sample data you have provided, I think more sample data would be helpful to check the whole scenario.
I have 2 vectors in which elements of a similar value are considered to be of the same group, something like this:
V1 V2
1 7
1 8
1 8
1 8
1 9
2 10
3 11
3 11
3 11
3 12
4 12
4 12
In this example, V1 has 4 groups, group 1 has the first 5 elements , group 2 has the next 1 element, group 3 has the next 4 elements, and group 4 has the last 2 elements. V2 has 5 groups, group 1 has the first element, group 2 has the next 3 elements, etc.
Now, I would like to count the number of time an element switches groups, using V1 as the reference. Let's consider group 1 in V1. The first 5 elements are in this same group. In V2, that's no longer the case because V2(1,1) and V2(5,1) do not have the same value as the remaining elements and thus are considered to have switched/changed membership. Applied the same principle, there is no switch for group 2 (i.e.,V1(6,1) and V2(6,1)), one switch for group 3, and no switch for group 4. Total is 3 switches.
At first I thought this would be a simple calculation with no. of switches = numel(unique(V1)) - numel(unique(V2)). However, as you can see, this underestimates the number of switches. Does anyone have a solution to this?
I also welcome a solution to a simpler problem in which V1 contains only one group, like this:
V1 V2
2 7
2 8
2 8
2 8
2 8
2 8
2 8
2 9
2 8
2 10
2 10
2 8
In this second case, the count is 4 nodes that switch: V2(1,1), V2(8,1), V2(10,1), V2(11,1).
Side note: this is actually a network problem: V1 and V2 are partitions and I'm trying to count the number of time a node switches membership.
Here is a solution using unique and accumarray
u = unique([V1 V2],'rows');
switches = accumarray(u(:,1) , 1, [],#numel)-1;
total_switches = sum(switches)
or you can use histcounts
u = unique([V1 V2],'rows');
switches = histcounts(u(:,1) , [unique(u(:,1)); u(end,1)])-1;
total_switches = sum(switches)
i can't solve one pascal problem, first i have to enter N which is the number or mesurments, next i enter those mesurments (if N is 5 i enter 5 mesurments for exmaple 3 4 5 6 7). After that i enter Q which is the number of times i check the number of different numbers in a specific part of the row. For example you have input
5 (number of mesurments)
1 2 3 3 4 (mesurments)
3 (number of checkings)
1 3
3 4
1 5 (left number is the starting number from the row, if it's 1 you start from 1, if it's 4 you start from 3 because 3 is the fourth mesurment and the right number is the last number if it's 5 it would be 4 because 4 is the fifth in the row)
And for output you would get
3
1
4 (for the first checking you have number from 1 to 3 (1 2 3) and you have 3 different numbers, second mesurment from 3 to 4 (3 3) and it's 1 different number and last from 1 to 5 there are 4 different numbers)
Hope you understod me, and thanks if you can solve it, i am in highschool now and i am preparing my self for something more complicating :) thanks in advance
The inequality operator of Pascal is <>
Here is my problem. I have crystal 12.1 connected to an access database. I would like to create a crosstab to compare current year sales with prior year. I was able to create the initial cross tab, but I cannot figure out how to add the year(s) under the store name. Here is what I would like it too look like. (CY is current year, PY is prior year)
Store 1 Store2 Store3 ...
---------- --------- --------
CY PY CY PY CY PY
Toys 2 3 4 3 7 7
Clothes 1 4 3 8 8 2
Shoes 2 2 4 5 6 9
I have the store name and CY salses in the crosstab now. I have no idea how to add the the PY header and values. My crosstab has the Store in the columns and the summarized fields have the Toys, Clothes, Shoes, etc values.
Simply add your date field into the columns area of the cross-tab expert (below the store field).
The highlight and click group options, set it to group on year.