Spotfire: how to get the First and last value in a column based on entity and date? - spotfire

I have a simple table with two entities and values associated with dates.
I want to extract the FIRST and LAST value based on historical dates. In the underlying data table, the dates are not sorted, hence when using FIRST() and LAST(), Spotfire gives incorrect values. What is the best way to solve this?
I tried
First([Value) OVER (Intersect([Category],[Date]))
Sample of the dataset:

If your using a cross table you can use a nested If statement to return the values when date is Min and Max.

Related

How can I transpose and summarize data appropriately in PowerQuery?

I'm working on achieving the following data transformation/wrangling within Power Query but can't seem to get there on my own. i have read a lof of different questions and answers on the forum but it seems just a bit beyond my grasp.
I have a table which has the ticker of a specific currency in the first column.
There is a second column with the date and time when a certain event, related to that specific currency, happens. This second column is basically the different 5-minute intervals which exist on any given day.
Finally there is a third column which describes the magnitude of the event.
The table therefore looks like this
What I would like to do in power Query is transpose the uniques name of the currencies as the first row of a new table. The first column of this table would be the largest time interval for any given currency. In this case, as you can see in the data I am attaching, the largest timeseries would be that of the currency ETH. Using the longest calendar as our first column I would then like to place the values described in item 3 above as rows in the new table.
The new layout would look like this
My steps to transform the raw data in the first table are detailed in this image. Basically just expanding a JSON file and getting all the data I need into that first format which I described previously.
What I then do is:
Pivot using the first column
Transpose
That gives me a whole bunch of new columns. Way more than I want. Any idea what I can do differently?
In powerquery,
click select pair column
Transform .. pivot column .. values column: basis advanced options: do not aggregate
code:
#"Pivoted Column6" = Table.Pivot(YourPriorStepName, List.Distinct(Source[pair]), "pair", "basis", List.Sum)
output:

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])

Change date format on category axis in my PowerPivot column chart

I'm trying to show values based on date on a PivotChart (column) in Excel. The problem is that the category label does not seem to follow the number formatting I set. Yes, the underlying table is formatted as date type. I've Googled a bit and the fix that seems to work for most people is to have complete data set (no holes or empty cells). My dataset is complete, so it doesn't help me.
Any ideas?
If you want guaranteed consistency of display format, make a display date string in your date dimension that is formatted the way you like. Use this for labels in pivot tables and charts.
You will also have to sort this field by your date field in the model to make sure they display in chronological order.
This is not possible with data linked from a PowerPivot data model. It is something Microsoft has been aware of for a long while but unfortunately they haven't implemented the functionality you desire.
There is, however, one work around: you can create a calculated column using =FORMAT(<date>,"<date format>"). If you use the formated column instead of your usual date column the axis will be formatted according to your needs.
This is old, but creating a calculated column using =FORMAT(,""), With this approach you lose the ability to sort the Axis in proper date order.

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