INDEX/MATCH approximate match without sorting - excel

Let's assume a simple table:
I would like to find provider name for a given person_id before a specified date. For example if I specify 1/1/2015 the output should be "Third".
It's easy enough to do so if the table is sorted by person_id and descending by the status date (as on the picture above), but is there a way to do it without sorting the table in any way?

The nearest date before the specified for person can be found by the following array formula:
{=INDEX(Table2[provider],MATCH(1,--(MAX(((A20=Table2[person_id])*(B20>Table2[status_date])*(Table2[status_date])))=Table2[status_date])*(A20=Table2[person_id]),0))}

I don't have a direct answer, but you might investigate Power Query and this link:
https://community.powerbi.com/t5/Desktop/How-do-I-pass-parameters-to-my-SQL-statement/td-p/118716
(Courtesy of Greg_Deckler - https://community.powerbi.com/t5/Desktop/How-do-I-pass-parameters-to-my-SQL-statement/td-p/118716)
Essentially, the premise is to use Power Query to "build/extract" a sub-table (and sort it) on the fly...
Hope that helps.

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.

How do I create a measure in Power Pivot that pulls a value from another table?

I have two tables that use a unique concatenated column for their relationship. I simply want to make a measure that uses the values from C4 of Table1. I thought I could use a simple formula like =values(Table1[C4]) but I get an error of "A table of multiple values was supplied where a single value was expected."
Side note: I realize the concatenation is unnecessary here in this simple example, but it is necessary in the full data I am working with which is why I added it into this example.
Here's a simplified set of tables for what I am trying to do:
Table1
Table2
Relationships
First you should think. Do I really need a Calculated column? Can't this be calculated at runtime?
But if you still want to do it, you can use RELATED or RELATEDTABLE.
Keep in mind if you are pulling from RELATEDTABLE, returns many values. So you should apply some type of aggregation like SUMX or MAXX.
You can use context transition to retrieve the value.
= CALCULATE(MAX(Table1[C4])

Expressing percentage

I need to be able to divide the values of each record in a certain field contained in a query result by the sum of all the values in the same field. This will enable me to calculate the percentage that each record is of the whole. The results must be expressed in the same domain in a new field.
That is: Each record in ColumnA must be divided by the sum of ColumnA, then expressed as a fraction/percentage in a new, neigbouring ColumnB.
I have tried this in Query1:
Total: (select sum(ColumnA) from Query1) - then in a second subquery Percentage:([CountOfColumnA/Total])
This worked once, but Access stopped me with a circular error because of the Query1 from Query1.
Now I am trying to rewrite it and reach the answer in only one subquery to avoid the circular problem. I can easily do this in Excel, but don't know enough about expressions and coding to manage it in Access.
I found a question on this forum from someone with a similar question, but I do not understand the answer - I do not know enough about SQL (nothing actually) to adapt it to my problem. My adaptation was something like this:
SELECT Query1, ColumnA / ((SELECT SUM(ColumnA) FROM Records) AS Percentage FROM Records
Assuming Query1 is a strange field name, try with:
Select
Query1,
ColumnA,
ColumnA / (Select Sum(T.ColumnA) From Records As T) As
Percentage
From
Records

Calculating the difference between the count of two date fields

I have data that is provided to me that includes the routed date and the service restoration date. From that it's pretty easy to generate a pivot table that generates a table with the date of the month, then a count of received tickets (routed), and the count of closed tickets. I'm trying to generate a calculated field (Pivot -> Options -> Fields, Items & Sets -> Calculated Field) to derive the delta.
When I use =Received - Closed, I get the difference in date rather than the delta in the counts. Can anyone point me in a direction on how I may calculate it? If it was static content it would be easy peasy, but I'm not getting the knack of doing this with a pivot table. Also I could achieve something similar with a countif type command and run it from a static calendar type table (which is what I'll probably end up doing if this ends up being a dead end).
As a solution, you can copy the pivot table and paste it as values in the new sheet. Do you math on values instead of on pivot.
I don't know if formatting your results in the pivot as NUMBER would help.. But you can try that as well.
I was unable to determine a way outside of what was mentioned above by Andrew. I've set up a static date list for the calendar month and then use a series of countifs instead of a pivot table to generate the output. Thanks to all who reviewed the question and to Andrew for his responses.

How do I SUMIF one PowerPivot table according to the rows of a second PowerPivot table?

I have two tables: one of customers ("Donor"), and one of transactions ("Trans"). In Donor, I want a "Total" column that sums all the transactions by a particular Donor ID, which I would calculate in a standard Excel table thus:
=SUMIF(Trans[Donor ID],[#ID],Trans[Amt])
Simple! How do I do the same thing with a DAX formula? I thought
=CALCULATE(SUM(Trans[Amt]),Trans[Donor ID]=[ID])
would do it, but I get the error
Column "ID" cannot be found or may not be used in this expression.
Strangely, when I use
=CALCULATE(SUM(Trans[Amt]),Trans[Donor ID]=3893)
I do get the total for ID 3893.
Eschewing CALCULATE, I did find that this works:
=SUMX(FILTER(Trans, Trans[Donor ID]=[ID]),[Amt])
...but it only allows the one filter, and I'll need to be able to add more filters, but:
=SUMX(CALCULATETABLE(Trans, Trans[Donor ID]=[ID]),[Amt])
...(which I understand is like FILTER but allows for multiples) does not work.
Can you identify what I'm doing wrong?
After putting together a quick model that looks like this:
I've confirmed that this DAX forumla works as a Calculated Column in the Donor table:
=CALCULATE(SUM(Trans[Amt]), FILTER(Trans, Trans[Donor] = Donor[DonorKey]))
The key here is to make sure that the relationship between the two tables is correctly configured, and then make sure to use the combination of CALCULATE() and FILTER() -- filtering the trans table based on the current donor context.

Resources