PowerPivot DAX - Dynamic Ranking Per Group (Min Per Group) - min

I am searching for a method to utilize within Microsoft PowerPivot 2010 that will allow me to perform dynamic ranking that will automatically update the associated rank value based on filters and slicer values that are applied.
Thusfar, all examples I have seen utilize the Calculate() DAX function that overrides existing filters within the PowerPivot table via the All() function which causes predefined filters that users may apply to be disregarded.
To illustrate my requirements, please reference the example below:
(Source Data within PowerPivot Window:)
-------------------------------------------------------------------------------------
Claim Number | Claimant Number | Transaction Date | Dollar Amount
------------------------------------------------------------------------------------
ABCD123456 4 1/1/2012 $145.23
ABCD123456 4 8/1/2012 $205.12
ABCD123456 4 9/1/2012 $390.74
VDSF123455 2 3/5/2012 $10.12
VDSF123455 2 9/5/2012 $50.12
VDSF123455 2 12/9/2012 $210.45
------------------------------------------------------------------------------------------
Now, I would like to have the capability of ONLY displaying the dollar amount for each claim number and claimant number based on the FIRST transaction date. I would essentially desire to only show dollars tied to the first transaction tied to each claim# and claimant number group.
My thought process was to create a dynamic rank for each [claim number + claimant number] group similiar to the "partition by - Row_Number()" function. In this way, each [claim number + claimant number] group containing a rank value of 1 would represent the FIRST transaction tied to this value.
However, I would need this rank value to change if a user applies a filter against the data within the resulting PivotTable.
This can be illustrated below based on the sample data defined above:
----------------------------------------------------------------------------------------------
Claim Number | Claimant Number | Transaction Date | Dollar Amount | Rank |
---------------------------------------------------------------------------------------------
ABCD123456 4 1/1/2012 $145.23 1
ABCD123456 4 8/1/2012 $205.12 2
ABCD123456 4 9/1/2012 $390.74 3
VDSF123455 2 3/5/2012 $10.12 1
VDSF123455 2 9/5/2012 $50.12 2
VDSF123455 2 12/9/2012 $210.45 3
------------------------------------------------------------------------------------------------
Now, if a user applies a filter via a slicer or via the filter dropdown within a PivotTable or within the PowerPivot table itself excluding valuation dates < 2/1/2012, the rank value should automatically update itself and be reflected as shown below:
(Filters applied)
=============================================================================
Claim Number | Claimant Number | Transaction Date | Dollar Amount | Rank |
============================================================================
ABCD123456 4 8/1/2012 $205.12 1
ABCD123456 4 9/1/2012 $390.74 2
VDSF123455 2 3/5/2012 $10.12 1
VDSF123455 2 9/5/2012 $50.12 2
VDSF123455 2 12/9/2012 $210.45 3
===========================================================================
As you can see, the rank value was automatically updated for the first claim group based on one of the rows tied to claim number ABCD123456 being hidden, based on the user applied filter.
I would then like to create an additional measure within the PowerPivot table that would display the dollar amount ONLY tied to the transaction containing a rank value of 1 as shown below:
(Filters applied, New Measure Added)
===============================================================================================
Claim Number | Claimant Number | Transaction Date | Dollar Amount | Rank | Opening Dollar Amt|
================================================================================================
ABCD123456 4 8/1/2012 $205.12 1 $205.12
ABCD123456 4 9/1/2012 $390.74 2
VDSF123455 2 3/5/2012 $10.12 1 $50.12
VDSF123455 2 9/5/2012 $50.12 2
VDSF123455 2 12/9/2012 $210.45 3
===============================================================================================
A corresponding Pivot Table could then be created referencing this data so that the "Opening Dollar Amt" measure would only represent dollars tied to the FIRST transaction per group as outlined above.
I would greatly appreciate if someone can outline how this could be accomplished.
I thought the dynamic ranking approach might be a good idea for this, but if anyone has a better idea to achieve my end result/goal which is to simply obtain the dollar amount tied to the first transaction "VISIBLE" (based on any user applied filters) PER GROUP I would be open ears to whatever approach you may have.

Although this is a well written question that you've obviously put time into formulating, you should read this about cross posting in forums. This is a clear duplication of something you've posted on MSDN at exactly the same time. I've answered in both seeing as its a decent question.
Firstly I created a basic measure [Amount] to sum the dollar amount column. I then used that within RANKX() to create the following:
[Rank] = RANKX(
FILTER(
ALLSELECTED(Table1),Table1[Claimant Number]=max(Table1[Claimant Number])
),
[Amount],
,1)
The key is the table that the [Amount] measure is iterated over - ALLSELECTED() just brings the stuff in the current filter context into play and the expression within the FILTER() restricts the table to the current claim number.
After that it was a simple task to return the [Amount] based on whether or not the [Rank] was 1:
[Opening Balance] = if([Rank]=1,[Amount],BLANK())
Hope this makes sense, I posted my workings on SkyDrive if they help.
Jacob

Related

Create SQL flag for entries based on changing value across dates

I have a table with application data where some applications turned into loans of either A or B type. My goal is, for each new application, to pull previous entries from the same Primary ID that turned into a loan and flag whether that ID has had either A, B, or both loan types. I'm struggling most with the time sensitivity element since I would have to pull loans from a subquery based on Funded Date referencing the Created Date from each row of the original table (or at least, that's the route I've focused on so far).
Here's what the original table looks like for one ID:
Primary ID
Application ID
Created Date
Funded Date
Loan Type
1
1
1/1/19
1/5/19
A
1
2
2/3/19
N/A
N/A
1
3
2/10/19
2/15/19
B
1
4
2/25/19
N/A
N/A
Essentially I'd want to add flags to each row that conveys this info:
Primary ID
Application ID
Created Date
Funded Date
Loan Type
Loan History
1
1
1/1/19
1/5/19
A
N/A
1
2
2/3/19
N/A
N/A
A
1
3
2/10/19
2/15/19
B
A
1
4
2/25/19
N/A
N/A
A, B
Thanks in advance

In UniQuery, how do you get the count of unique values found while doing a BREAK.ON

I know I can get the counts for how many individual entries are in each unique groups of records with the following.
LIST CUSTOMER BREAK-ON CITY TOTAL EVAL "1" COL.HDG "Customer Count" TOTAL CUR_BALANCE BY CITY
And I end up with something like this.
Cust...... City...... Customer Count Currently Owes
6 Arvada 1 4.54
********** -------------- --------------
Arvada 1 4.54
190 Boulder 1 0.00
1 Boulder 1 13.65
********** -------------- --------------
Boulder 2 13.65
...
============== ==============
TOTAL 29 85.28
29 records listed
Which becomes this, after we suppress the details and focus on the groups themselves.
City...... Customer Count Currently Owes
Arvada 1 4.54
Boulder 2 13.65
Chicago 3 4.50
Denver 6 0.00
...
============== ==============
TOTAL 29 85.28
29 records listed
But can I get a count of how many unique grouping are in the same report? Something like this.
City...... Customer Count Currently Owes City Count
Arvada 1 4.54 1
Boulder 2 13.65 1
Chicago 3 4.50 1
Denver 6 0.00 1
...
============== ============== ==========
TOTAL 29 85.28 17
29 records listed
Essentially, I want the unique value count integrated into the other report so that I don't have to create an extra report just for something so simple.
SELECT CUSTOMER SAVING UNIQUE CITY
17 records selected to list 0.
I swear that this should be easier. I see various # variables in the documentation that hint at the possibility of doing this easily but I have never been about to get one of them to work.
If your data is structured in such a way that your id is what you would be grouping by and the data you want is stored in Value delimited field and you don't want to include or exclude anything you can use something like the following.
In UniVerse using the CUSTOMER table in the demo HS.SALES account installed on many systems, you can do this. The CUSTID is the the record #ID and Attribute 13 is where there PRICE is stored in a Value delimited array.
LIST CUSTOMER BREAK-ON CUSTID TOTAL EVAL "DCOUNT(#RECORD<13>,#VM)" TOTAL PRICE AS P.PRICE BY CUSTID DET.SUP
Which outputs this.
DCOUNT(#RECORD<13>,#
Customer ID VM)................. P.PRICE
1 1 $4,200
2 3 $19,500
3 1 $4,250
4 1 $16,500
5 2 $3,800
6 0 $0
7 2 $5,480
8 2 $12,900
9 0 $0
10 3 $10,390
11 0 $0
12 0 $0
==================== =======
15 $77,020
That is a little juice for a lot of squeeze, but I hope you find it useful.
Good Luck!
Since the system variable #NB is set only on the total lines, this will allow your counter to calculate the number of TOTAL lines, which occur per unique city, excluding the grand total.
LIST CUSTOMER BREAK-ON CITY TOTAL EVAL "IF #NB < 127 THEN 1 ELSE 0" COL.HDG "Customer Count" TOTAL CUR_BALANCE BY CITY
I don't have a system to try this on, but this is my understanding of the variable.

How to group rows vertically in PowerBuilder?

I have this sample rows of plate nos with bay nos:
Plate no | Bay no
------------------
AAA111 | 1
AAA222 | 1
AAA333 | 2
BBB111 | 3
BBB222 | 3
CCC111 | 1
Is there a way to make it look like this in a datawindow in powerbuilder?
1 | 2 | 3
------------------------
AAA111 | AAA333 | BBB111
AAA222 BBB222
CCC111
There isn't an simple answer, especially if you need cells to be update-able.
Variable Column Count Strategy
If the number of columns across the top is unknown at development time than you might get by with a "Crosstab" style datawindow but it would be a display only. If you need updates you'll need to do manual data manipulations & updates as each cell would probably represent one row.
Fixed Column Count Strategy
If the number of columns is known (fixed) you could flatten the data at the database and use a standard tabular (or grid) datawindow control but you'll still need to get creative if updates are needed.
If you use Oracle to obtain the data you can use the Pivot and Unpivot function to perform what you are looking for. Here is an example of how to do it:
http://www.oracle.com/technetwork/es/articles/sql/caracteristicas-database11g-2108415-esa.html

Use excel and vba pivot tables to summarize data before and after dates

I have an excel document that is an dumped output of all service tickets(with statuses, assigned to, submitted by...etc) from our ticket tracking software. There is one row per ticket.
I am trying to make a flexible report generator in vba that will allow me to take in the ticket dump and output a report which will have a copy of the data in one sheet, a summary in another sheet, and a line graph in another sheet.
I feel like a pivot table is the perfect approach for this, the only problem is in the summary.
The data from the ticket dump looks something like this:
| Submitted_On | Priority | Title | Status | Closed_On |
10/10/2016 1 Ticket 1 New
10/11/2016 1 Ticket 2 Fixed 11/10/2016
10/12/2016 3 Ticket 3 Rejected 11/9/2016
10/15/2016 1 Ticket 4 In Review
The problem is the way I want the summary to look. Basically the summary should show all tickets that were opened and closed at the first of every month at exactly midnight within the past three years. In other words, if this report was a time machine, at that exact time X would be open and Y would be closed. Furthermore, The summary table should break that down by priority.
The hard part is that these simulated report dates (first of every month within the last 3 years) are extraneous values and are not within each data row.
So the report would be like this:
| Open | Closed |
| Reporting Date | P1 | P2 | P3 | P1 | P2 | P3 |
1-Oct-2016 6 10 0 3 2 0
1-Nov-2016 4 10 0 5 2 0
1-Dec-2016 6 3 0 5 9 0
Basically the formula for the Open section would be something like:
priority=1 AND Submitted_On<Reporting Date AND (Closed_On>Reporting Date OR Closed_On="")
and the formula for the closed section would be something like:
priority=1 AND Submitted_On<Reporting Date AND Closed_On<Reporting Date
It would be needed where I can filter the data so that its only coming assigned to x or only with these statuses...etc. which is why I don't think a regular sheet with formulas would work.
I thought pivot tables would work but Reporting Date isn't a field.
Do you have any advice as to what I can do to make this report work and be very flexible as far as filtering goes?
Thank you!
P.S. I am using excel 2010, so I do not have access to queries

Excel: filtering a time series graph

I have data that looks like the following:
ID | Location | Attendees | StartDate | EndDate
---------------------------------------------
Event1 | Bldg 1 | 10 | June 1 | June 5
Event2 | Bldg 2 | 15 | June 3 | June 6
Event3 | Bldg 1 | 5 | June 3 | June 10
I'd like to create a time series graph showing, for every given date, how many events were active on that date (i.e. started but haven't ended yet). For example, on June 1, there was 1 active event, and on June 4, there were 4 active events.
This should be simple enough to do by creating a new range where my first column consists of consecutive dates, and the second column consists of formulas like the following (I hardcoded June 8 in this example):
=COUNTIFS(Events[StartDate],"<=6/8/2009", Events[EndDate],">6/8/2009")
However, the challenge is that I'd like to be able to dynamically filter the time series graph based on various criteria. For example, I'd like to be able to quickly switch between seeing the above time series only for events in Bldg 1; or for Events with more than 10 attendees. I have at least 10 different criteria I'd like to be able to filter on.
What is the best way to do this? Does Excel have a built-in way to do this, or should I write the filtering code in VBA?
Apart from that my answer is not programming related: That's prime example for using a pivot table. Use this to show data consolidated for e.g. each day. Then you can play around with filtering as you like.
Your question is exactly what pivot tables are made for.