DAX Rank by Date - excel

I am Counting on Distinct ID's in a column - this is leading to the sum of the subtotals not equalling the grand total as follows:
What I want to do is rank the Payment Dates in cronological order and select ONLY the highest date to display. In the example above the Grand Total won't change, but the Townville row will not show a Distinct Student Count.
This is a very specific requirement and I'm assuming there's an easy way to do it in DAX - I've tried playing around with both RANKX and MAX but am no closer to solving this.
One last thing - the Rank must be contextual to the Time Filter selected by the user (so if they select 2015 it'd give the second record Rank 1 and the top record wouldn't show. If they select May 2015 it'd give the top record Rank 1 and the second record wouldn't show)

I think this is what you are looking for - I added a calculated column to the PowerPivot model that provides a rank based on the Last Payment Date and the Name of the Student. It will rank the earliest payment for any student as a 1.
The code for the column is as follows:
=RANKX(FILTER(Table1, [Student Name] = EARLIER([Student Name])), [Last Payment Date])
... assuming your table is named "Table1"!
The FILTER is the key that limits the ranking to dates belonging to students with that name only.
Update for Multiple tables
To set up relationships between the tables, go to the "Diagram View" of the model, available in the Home tab of the Power Pivot window.
You can drag fields from one table to the other to create relationships. This will only work if at least one of the fields is unique - it's a good idea to think of the model as a dimensional model, with a tables that acts like a fact and other tables around it that act like dimensions.
From the comment, I would try to get the Payments to act like the fact, and have it link to the Community and Student tables. in this case, you could then have the following code:
=RANKX(FILTER(Table1, Related('Students'[Student Name]) = EARLIER('Students'[Student Name])), [Last Payment Date])
This calculated column would be on your Payments Fact table, and it uses a lookup to a related field.
Note that in this specific case, it would be easier to just run the filter over your Student ID field that is used to lookup the Student name.

Related

DAX Measure - Specific Ranking using RANKX

I have a table that just contains all articles.
Then I have a transactional table that contains a value that I would like to use for the rank. THe same tables has the department information.
The structure is like:
Now I would like to get the Ranking based in Value, in the end represented in a matrix.
This function shows me the ranking based on the value:
RANKX(ALLSELECTED(Article),[Value])
If the matrix just contains Article in the rows, then it works.
But when I add department, then the Rank is calculated for each department.
How can I get the RANK for each Article regardles of the Department?
I'm assuming that you are creating a measure and that you are putting the results in a "table", rather than a "matrix". If so, then the following DAX works for me.
Rank = RANKX(ALLSELECTED(Table1), Calculate(Max(Table1[Value])))
Note that this is when all of the data comes from a single "Table1". You may need to make updates to the measure above based on your table structure and names.

Dynamic Grouping in Power BI/PowerPivot Model based on a calculated field

We are trying to create a model in Excel/Power BI (using Power Query or Power Pivot or anything that would work) in order to classify a customer by its best product (based on a ranking system).
The first approach we applied was to count the customers per minimum ranking (or per best product brand). (inspired from the blog https://stackoverflow.com/questions/15742186/powerpivot-dax-dynamic-ranking-per-group-min-per-group)
Below the steps we did exactly:
- In PowerPivot Model, we created Classification and Customers table like in the example further below.
In the same model, we added a calculated column with the following formula to obtain the minimum rank per customer.
=MINX (
FILTER ( ALLSELECTED ( Customers ); [Customer_ID] = EARLIEST ( [Customer_ID] ) );
[Ranking]
)
Within a pivot table in Excel, we’ve put the calculated column in rows.
Then, we’ve used a Count distinct aggregation of the customers in the pivot table values.
 This gave me the first desired result. (below example Pivot_Table.Selection1)
Now, the issue comes when we want to add more analysis axis.
For example, besides the product brand, we want to have the Product type in columns, and we want our measure to be recalculated every time I add/delete an axis.
In other words, we want to have a distinct customer count per best product and per Product Type.
In addition, we want the second attribute (axis) to be variable and the grouping or the distinct count per group to be dynamic.
Example:
Let’s suppose we have the tables Classification and Customers in our Model:
In the first approach we tried, we got the following table: Pivot_Table.Selection1:
Now when we add the analysis axis, we would like to have the following example: Pivot_Table.Selection2:
But we are having this:
As you can see, there should be one customer for the Group “Mercedes” and one for “Renault”, since depending on the product type, the top Truck for customer A is Renault and its top Car is “Mercedes”.
However, in the pivot table, the Mercedes group is shown as Truck (which doesn’t even exist in our dataset).
Edit
I'm open for any suggestion, not only Power Pivot, but also Power Query (M functions) or Power BI or whatever could work.
Finally I think I understood your problem, a customer can have different Product_Brand values, you want to count only those Product_Brand which its ranking is the minimum.
In that case, this is a possible solution:
Create a calculated column called Minimum Rank in the Customer table.
=
CALCULATE (
MIN ( [Ranking] );
FILTER ( Customer; [Customer_ID] = EARLIER ( Customer[Customer_ID] ) )
)
Then create a measure, lets say Customer ID Distinct Count to count those rows where the Rank is equal to the minimum for that customer.
Customer ID Distinct Count :=
CALCULATE (
DISTINCTCOUNT ( Customer[Customer_ID] );
FILTER ( Customer; [Ranking] = [Minimum Rank] )
)
You will get something like this:

Unable to Create a Sub-Total in the POWERPIVOT

I am pretty new with POWERPIVOT tables. I have searched for a bit of time now to resolve my problem but I have been unsuccessful so far. As you can see below, I have created a POWERPIVOT table in Excel 2013 that is composed of two FACT tables, which are based on: 1) a sheet where the clients can insert vote 1 budget entries; and, 2) another sheet where the clients can insert vote 5 budget entries. Also, a few DIMENSION tables have been added to the combination in order to link the Branch names and the expenditure type. Please note that this is only a simple example of what I am trying to produce.
However, my main problem is that I can't add a sub-total that would sum Salary, Operating and Revenues for Vote 1 and Vote 5 separately. What I would like to show is the following:
Please note that I have tried calculated columns and calculated fields at the best of my knowledge but the results are always showing another set of columns for Salary, Operating and Revenues but what I need is just one column that sum the three components so it displays Salary, Operating, Revenues and Sub-Total. Does anyone know how to resolve this problem that I am facing since a long time?
Thanks to gurus.
I would suggest that you start by putting both budgets in the one table and an extra column to designate Vote id., Otherwise I fearyou will need to add a calculated column concatenating the Branch and Expenditure Type in each table, then doing a LOOKUPVALUE from Vote1 on the concatenated column to Vote5 and pull back the value.

How to get Excel Pivot 'Summarize by' to return actual data values not sum, avg, etc?

I am using Excel Powerpivot with data in two separate tables. Table 1 has ITEM level data with a BRAND characteristic. Table 2 has BRAND level data. The two tables are linked by the BRAND key. The measure I am using is non addable. i.e. the sum of the ITEMS does not equal the BRAND. The pivot is set up with ITEMS nested under BRANDS in the rows and the Measure in the column.
Excel assumes that I want to summarize ITEM to a BRAND level by applying SUM, MAX, MIN, AVG, etc. I would like to return the actual values from the appropriate ITEM or BRAND level table and not apply any calculations to the values. Is this possible?
If what you are effectively trying to do is produce a different result for the Brand rows (e.g. blank()) then the answer is to write a further measure that does a logic check to determine whether or not the row in question is an ITEM or a BRAND.
= IF (HASONEVALUE(table1[Item]), [Measure], Blank() )
Bear in mind that this will work for your current pivot but may not be adaptable to all pivots.
This assumes that you have explicitly created a measure called [Measure] and you are not just dragging the numeric column into the values box. If not you can create the initial [Measure] something like this:
= Sum(table1[Value])
Where Value is the column you want to use in the measure. Although you have used a sum, if it relates to a single item which has a single row in the table it will give the desired result.

Report on users who don't estimate well in Excel

I have a spreadsheet corresponding to entries of a user, their estimation, and the actual value (for example: hours for a particular project - again, this is only an example), which we can represent in CSV like:
User,Estimate,Actual
"User 1",5,5
"User 1",7,7
"User 2",3,3
"User 2",9,8
"User 3",6,7
"User 3",8,7
I'm trying to build a report on these users, to quickly see which users underestimate or overestimate, and so I created a pivot table. But, I can't figure out how to simply show if a user has underestimated at some point. I tried to create a calculated field like =IF(Estimate > Actual, 1, 0), but this sums, then compares the Estimate and Actual columns and tells me that "User 3" doesn't over/underestimate.
Without adding an additional field to my data, how can I accomplish this?
A similar SQL pseudo-query would be:
SELECT DISTINCT al.User,
(SELECT COUNT(*) FROM ActivityLog AS l2 WHERE l2.User = al.User AND l2.Estimate > l2.Actual) AS Overestimates
FROM ActivityLog AS al
Edit:
I'm still working on this, and currently have created a static list of users in some cells on the side, and have given them the Array Formulas: {=SUM(IF((A$2:A20 = F6)*(B$2:B20 > C$2:C20), 1, 0))} and {=SUM(IF((A$2:A20 = F6)*(B$2:B20 < C$2:C20), 1, 0))} (if I have the user's name in F6).
Mainly, I want to do this where the list of users can populate dynamically from the main data.
Calculated fields in pivot tables stink. I would get rid of the pivot table and do it with formulas. Start a unique list of users in H15 and enter this in I15
{=MAX(($A$2:$A$7=H16)*($B$2:$B$7-$C$2:$C$7<>0))}
array entered. This will return 1 if they ever over or under estimated and zero if they never did. The downside is that you can't "refresh" it like a pivot table so you have to make sure your unique user list is accurate all the time.
If that's too big of a downside, I think you'll need to add a column to your source data. Specifically
=ABS(B2-C2)
And add that to your pivot table. It will show zero for never over/under and non-zero otherwise.
You are aware that you should make sure the estimates are all in the same range? Smaller numbers can be estimated better (when talking about hours).
Add a column for actual-estimate
then summarize those values for min max and average. (or stddev)

Resources