How to do calculated values in Excel Pivot Table - excel

I have a table like this:
Year Num Freq. Exam Grade Course
2014 102846 SM SM Astronomy 3
2015 102846 12,6 1,7 NC Astronomy 2
2017 102846 20 11,8 17 Astronomy 2
2015 102846 SM NC Defence Against the Dark Arts 4
2015 102846 11 4,5 NC Herbology 2
2015 102846 15 13,99 14 Herbology 2
I am trying to get the percentage of approved students (Grade >= 10) for each course by year and global average.
I've been trying for nearly 3 hours to do a calculated field but so far the only thing I could get was the sum of each student per year:
I have tried to do a calculated field with = Grade >= 10 hoping that it would give me a list of approved students but it gives me 1.
What am I doing wrong in here? It's my first time working with pivot tables.

I would really recommend to not mix string type (text) together with numbers. It's a horrifying idea and will cause a lot of headache when data will be used for calculations (both Freq. and Grade). Rather I would use 0 or some numeric value to represent the text.
Not recommended, but yes it's doable =)
You need some dummy variable to point out which row is number and which is text. So I created Grade Type. We can now count only the rows that have a number in the Grade column by using Grade Type = Number.
I create a table of the data and add the column Grade Type. I use this formula to get Grade Type:
=IF(ISNUMBER([#Grade]),"Number","Text")
I then create the following measures:
Nr of Approved Students
=COUNTX(FILTER(Table1, Table1[Grade Type]="Number"),
IF((VALUE(Table1[Grade])>=10),VALUE(Table1[Grade]),BLANK()))
First we filter which rows that should be evaluated (COUNTX(<table>,...)). If yes, then only count for rows that fulfill >=10, where VALUE() converts string number to numeric (COUNTX(...,<expression>)).
Nr of Student (w/ Grade Number)
=COUNTX(FILTER(Table1, Table1[Grade Type]="Number"), VALUE(Table1[Grade]))
Count all rows that have a number
Approved (% of Total)
=[Nr of Approved Students]/[Count of Grade]
Setup the PowerPivot Table
Create the PowerPivot and add the data to the data Model
Then create a new measure by clicking your pivot table and then "Measures" -> "New Measure..."
Fill in all the relevant data.
Result should be something like:

Related

DAX returning value based on SUM of multiple rows in other table

Good evening all!!
Here's a fun one. I've been pouring through some other posts and it feels like there are many permutations of this scenario but none that span tables, so I'm looking for some input.
Consider the following:
Table A has two fields: ID and TYPE. TYPE will be our value to populate.
ID Type
1
2
3
Table B has two fields: ASSOCIATED ID and HOURS.
Associated ID Hours
1 24
1 0
2 10
2 38
3 50
3 25
The requirement is to return a value of "LESS THAN 25" or "GREATER THAN 25" for TYPE in TABLE A based on the SUM of the HOURS in TABLE B for the ASSOCIATED ID. Ex: ASSOCIATED ID "1" in TABLE has value 24 and 0 for a sum of 24, returning "LESS THAN 25" for TYPE in item ID 1 in TABLE A.
Any and all suggestions will be attempted, thank you so much to the community for taking a look.
Make sure you have a relationship between the two tables by using the ID. Then enter this formula into a column in the ID table:
Type:=if(calculate(sum(TableB[Hours]))>25,"25 or More","Less than 25")
Try this one on 1-TYPE: (I am considering A1 Cell as the beginning of your table for both table, just place the real position)
=IF(SUMIF(TableB!$A$2:$A$7,"="&A2,TableB!$B$2:$B$7)>=25,"GREATER THAN 25","LESS THAN 25")
Then drag it down.

Cuberankedmember getting wrong order

I'm trying to create a top3 ranking from a data table varying metrics but each time I get the wrong order from the cuberankedmember, usually misplacing ranks 2 and 3.
The data I'm mostly focused on is regarding sales revenue. Power pivot sums all sales by store, quite straight forward.
From this I use a cubeset formula that captures store name, filtered by a month and year, which the user types in as any day for the month, and set the measure which to sort by (NTS) (code 1).
The cuberankedmember selects the cubeset and defines the position (code 2).
Then the cubevalue selects as members the cuberankedmember, filters once again month and year, then pulls in the measure (code 3).
E4 is the date
Code1 (cell C21):
=CUBESET("ThisWorkbookDataModel";
"NONEMPTY([Store_Dict].[Nome_DSR].children,
([Calendar].[Year].[All].["&YEAR($E$4)&"],
[Calendar].[Month Number].[All].["&MONTH($E$4)&"]))";
"Ranking";
2;
"[Measures].[NTS]")`
`Code2` (cell `D22`):
`=CUBERANKEDMEMBER("ThisWorkbookDataModel";$C$21;1;"a")
`C21` is the `CUBESET` formula
Code3:
CUBEVALUE("ThisWorkbookDataModel";
$D22;
"[Calendar].[Month Number].["&MONTH($E$4)&"]";
"[Calendar].[Year].["&YEAR($E$4)&"]";
"[Measures].[NTS]")
Actual Result:
Ranking Store NTS
1 a 606
2 c 425
3 b 428
Expected result:
Ranking Store NTS
1 a 606
2 b 428
3 c 425

How to hide a column in Tableau without hiding other column with same year

I use Tableau to do some report and my data source is excel live. I have an excel file that contains each selling records and it looks like this. the last two columns are year over year growth.
I want to hide the column highlighted in blue:
, without hiding any other column. Right now whenever I hide the highlighted column, the first column "2014 amount" also hides, but I want 2014 amount to display.
I know if I have quarters and months, there's a function to make the columns independent by combine year and quarter/month, but I only want the year. I know I can do it in two separated worksheet and put them together in one dashboard but I need to put them in one worksheet.
I tried to create a calculation field to calculate year 2015 year over year growth only, but I am not sure how to write the syntax. The logic would be:
Dim a,b,c, a = 2014 amount, b = 2015 amount, c = b/a-1
But I am not sure how to use tableau to do things like this.
You will have to remove the YEAR(Date) Dimension, and create 3 measures: one for 2014 sales, one for 2015 sales, and one with the delta. Otherwise, what you are trying to do will not work.
Thankfully, this is easy enough to do.
Create a measure for 2014 sales
SUM(CASE YEAR(DATE) WHEN 2014 THEN [Amount] ELSE 0 END)
Then a measure for 2015 sales
SUM(CASE YEAR(DATE) WHEN 2015 THEN [Amount] ELSE 0 END)
Then a delta measure
([2015 Amount] - [2014 Amount]) / [2014 Amount]
Then go ahead and drag them into your visual. Here's the result

How to calculate values dynamically from Excel table

I have a programming issue in Excel that I don't know how to solve it. I want to create an automatic Delivery Cost Program on Excel that will help me calculating the cost more easily.
The input variables are:
Quantity (Values for 1, 2-9,10-49,50+ and more)
Shipping method
Depending on the Quantity Value and Shipping method, Excel should lookup on the table and return the total shipping cost according the following Table:
------------------------------------------
Delivery | Per shipment fee
------------------------------------------
| 1 2-9 10-49 50+
------------------------------------------
Standard | 2,99 1,89 1,5 1,1
Expedited | 5,99 2 1,75 1,25
Priority | 10,99 3,39 2,25 1,35
------------------------------------------
Let me show you with some examples what I want to get:
1- Example:
- Quantity: 15
- Delivery: Expedited
- Total Cost = 15 * 1,75 = 26,25$
1,75$ is the returned value after looking on the table using the variable Quantity and Shipping Method.
I have tested doing =IF statements but sure that there is an easier way to do it.
I'm not very good on Excel programming so any help will be appreciated
Best regards and have a great day!
Assuming that your table has the delivery types in column A in rows 4 through 6 and that the quantities are in row 3 (columns B through E) the following formula should do it for you:
=INDEX(B4:E6,MATCH(B9,A4:A6,0),MATCH(C9,B3:E3,1)) * Quantity
Note, that the quantities in row 3 must be a number. So, the numbers should be 1, 2, 10, and 50 and not 1, 2-9, 10-59, 50+. There are two possibilities to achieve that:
Create a helper row and hide it (while only showing the row with the "names" as you wish for.
Change the number format on these cells: for the column containing the 2 the number format should then be "2-9" (custom number format). For the number 10 the number format would be "10-49" and the number format for the last column would be "50+". Like this you see what you wan to see while the cells still contain numbers only (for the upper formula to work correctly).

excel 2013 pivot table count sums greater than and less than

I have a large spreadsheet in Excel 2013 with student records. Each row corresponds to one student registered in one course. The spreadsheet spans 5 years of student records. I am trying to create a pivot table that shows me the distinct count of students who have 6 or more courses as well as those with fewer than 6 courses.
One row has the following fields (and many more): Student
Number Academic Year Course ID Calculated Field (as
above)
The pivot table will count unique student courses (ie. John Doe in Course A). I have a calculated field in my main data that combines Academic Year (ex. 2015), student number (ex. 345987) and Course ID (ex. 195100) into a field like AY2015SN345987CS195100. So, if student 345987 takes 7 different courses in 2015, I want that to count as 7. Then I create my pivot table with rows: Academic Year and Student Number; Values are Distinct Count of Calculated Field
I have created a pivot table that calculates all distinct student courses into something like this:
Year # of Students
+2015 501
+2014 640
+2013 465
...
If I expand my pivot table a bit more to individual student number rows, it looks like this:
Year # of Students
2015 501
345987 7
123765 5
...
I can also create a value filter (i.e. distinct count of courses is greater than or equal to 6) applied to the Student Number, so I meet one of my criteria (ex. 6 or more) into something like this:
Year 6 or More
2015 356
2014 458
2013 290
I can also filter and get those with less than 6 courses.
However, what I really want is to show the distinct count of those students that have 6 or more courses in one year and the distinct count of those students that have less than 6 courses into a single pivot table.
The final product would look something like one of these:
Year 6 or More Less than 6
2015 356 145
2014 458 182
2013 290 175
Data summarization with greater than and less than – Excel-Formula & PivotTable
Assuming the DATA is located at range B6:D176 with the following fields as described by the user (adjust range as required):
Student : Student Number
Year : Academic Year
Course ID
Key : Calculated Field
Objectives :
Classify within each year in the database the student population in two groups:
a. Students with 6 or more courses
b. Students with less than 6 courses
Summarize both groups for each year, showing for every year and each group the total of students and total of student\courses
I’m not sure that all calculations needed can be performed by a PivotTable, therefore I propose to use working fields to do the calculations then a PivotTable to summarize the results.
Working Fields :
Key : Let’s take out of this calculation the Course Id in order to have a field that contains the Year\Student combination.
Enter this formula in E7 then copy till last record
=CONCATENATE("AY",$C7,"SN",$B7)
AY.SN.CS.Cnt : Count of Year\Student\Course. Enter this formula in F7 then copy till last record
=COUNTIF($E$6:$E$176,$E7)
AY.SN.Cnt : Count of Year\Student. Enter this formula in G7 then copy till last record
=1*(COUNTIF($E$6:$E7,$E7)=1)
AY.SN.CS >= 6 : Quantity of records for Year\Student with 6 or more courses. Enter this formula in H7 then copy till last record
=1*($F7>=6)
AY.SN.CS < 6 : Quantity of records for Year\Student with less than 6 courses. Enter this formula in I7 then copy till last record
=1*($F7<6)
AY.SN >= 6 : Quantity of Students with 6 or more courses in a Year. Enter this formula in J7 then copy till last record
=1*($F7>=6)*$G7
AY.SN < 6 : Quantity of Students with less than 6 courses in a Year. Enter this formula in K7 then copy till last record
=1*($F7<6)*$G7
Fig. 1
The working fields can be hidden if it’s preferable to the user
Then create a PivotTable as per figure below
Fig. 2
The PivotTable reads that in Year 2015 there are:
3 Students with 6 or more courses AY.SN >= 6 and a total of 22 courses AY.SN.CS >= 6
3 Students with less than 6 courses AY.SN < 6 and a total of 10 courses AY.SN.CS < 6

Resources