Grouping similarly to MySQLs GROUP BY - tableau-api

I have a dataset which looks somewhat like this;
email minutes date
aaa#aaa.com 40 10-01-18
aaa#aaa.com 60 10-01-18
bbb#bbb.com 10 10-01-18
bbb#bbb.com 40 10-02-18
ccc#ccc.com 60 10-02-18
I wish to group by email and filter for total minutes per date > 80. So on 10-01-18 aaa#aaa.com has >80 but bbb#bbb.com has not.
How can this kind of filtering be achieved?

Create a calculated field :
{FIXED [email], [date] : SUM([minutes])}
Place it on the filters shelf >> All values >> 80 trashhold >> Ok
Now right click new filter pill and select option Add to context (so filter'll be applied before other calculations)

Related

How to create calculated field based on another time series

I have a set of prices as data source for given timeseries and I would like to create a calculated field by combining two prices for each date: i.e.,
Price A *5 - Price B.
Data source:
Date Product Price
01.01.2018 A 10
01.01.2018 B 15
02.01.2018 A 20
02.01.2018 B 30
03.01.2018 A 10
03.01.2018 B 30
I don't know how to write the formula correctly for the Calculated field.
What I expect is to build the following table:
Date A B Combined Price (A *5 - B)
01.01.2018 10 15 35
02.01.2018 20 30 70
03.01.2018 10 30 20
Thank you
Answer from Mohfooj can be found in Tableau forum here: https://community.tableau.com/message/900181#900181

MDX iif date greather than doesn't evaluate correctly in my cube

I have a problem which seems to be very simple to solve but I can't. In my Fact table I have a Timestamp field which is a smalldatetime Type. This fact is linked to a Time dimension via its fulldate_Fk (also SmallDatetime). So What I would like to have is to compare the timestamp with the FullDate_FK from the fact to create a calculation like this:
iif([Dim Time].[Date].CurrentMember.MemberValue <=
[Fact].[Timestamp].CurrentMember.MemberValue
,[measures].[YTD Actuals]
,[measures].[YTD Actuals]+[measures].[YTD Com])
But it is not working at all. All [Dim Time].[Date] seem to be evaluated as < than the Timestamp.
P.S: The Timestamp is the last date when the data have been loaded in the DB (in my case 31/08)
Here the result I got:
MONTH | YTD Actuals | YTD Com | Calculation;
JAN , 10 , 10 , 10;
FEB , 20 , 10 , 20;
MAR , 40 , 20 , 40;
MAY , 60 , 30 , 60;
JUN , 70 , 50 , 70;
JUL , 85 , 50 , 85;
AUG , 120 , 55 , 120;
SEP , 120 , 60 , 120;
OCT , 120 , 70 , 120;
NOV , 120 , 80 , 120;
DEC , 120 , 90 , 120;
From August, I should have the sum of Actuals YTD and Com YTD in the calculation, but I still have the Actuals YTD only?
Extra Info
I'm using PivotTable just by dragging attributes in Excel. Month in rows and measures (the 2 YTD and the new calculated member)
If you build a new calc which is:
[Fact].[Timestamp].CurrentMember.MemberValue
What does it return when you add it to your PivotTable? Null? I suspect the CurrentMember is the All member so MemberValue is null. But let's test that.
Do all rows in the fact table have the same Timestamp or are there many different timestamps?
If your fact table has 10000 rows are you expecting the IIf calc will be evaluated 10000 times (once for each row)? That's not the way MDX works. In your PivotTable that has 12 rows the IIf calc gets evaluated 12 times at the month grain.
If you want the calculation to happen on each of the 10000 rows then write the calculation in SQL and do it in a SQL view before it gets to the cube.
To make the calc work as you intend in the cube consider doing the following. Add a new column in your DimTime SQL table called Today Flag. It should be updated during the ETL to be Y only on the row which is today and should be N on other rows. Then add that column as a new attribute to your Dim Time dimension. You can make it Visible=False. Then go to the Calculations tab and flip to the Script view and replace your current [Measures].[Calculation] calc with this:
Create Member CurrentCube.[Measures].[Calculation] as
[measures].[YTD Actuals];
Scope({Exists([Dim Time].[Month].[Month].Members,[Dim Time].[Today Flag].&[Y]).Item(0).Item(0):null});
[Measures].[Calculation] = [measures].[YTD Actuals]+[measures].[YTD Com];
End Scope;

Qlikview - Data between dates; filter out data past or future data depending on selected date

I've seen threads where the document has Start Date and End Date "widgets" where users type in their dates, however, I'm looking for a dynamic solution, for example on the table below, when I select a date, say "1/1/2004", I only want to see active players (this would exclude Michael Jordan only).
Jersey# Name RookieYr RetirementYr Average PPG
23 Michael Jordan 1/1/1984 1/1/2003 24
33 Scotty Pippen 1/1/1987 1/1/2008 15
1 Derrick Rose 1/1/2008 1/1/9999 16
25 Vince Carter 1/1/1998 1/1/9999 18
The most flexible way is to IntervalMatch the RookieYr * RetireYr dates into a table of all dates. See http://qlikviewcookbook.com/recipes/download-info/count-days-in-a-transaction-using-intervalmatch/ for a complete example.
Here's the interval match for your data. You'll can obviously create your calendar however you want.
STATS:
load * inline [
Jersey#, Name, RookieYr, RetirementYr, Average, PPG
23, Michael Jordan, 1/1/1984, 1/1/2003, 24
33, Scotty Pippen, 1/1/1987, 1/1/2008, 15
1, Derrick Rose, 1/1/2008, 1/1/9999, 16
25, Vince Carter, 1/1/1998, 1/1/9999, 18
];
let zDateMin=37000;
let zDateMax=40000;
DATES:
LOAD
Date($(zDateMin) + IterNo() - 1) as [DATE],
year( Date($(zDateMin) + IterNo() - 1)) as YEAR,
month( Date($(zDateMin) + IterNo() - 1)) as MONTH
AUTOGENERATE 1
WHILE $(zDateMin)+IterNo()-1<= $(zDateMax);
INTERVAL:
IntervalMatch (DATE) load RookieYr, RetirementYr resident STATS;
left join (DATES) load * resident INTERVAL; drop table INTERVAL;
There's not much to it you need to load 2 tables one with the start and end dates and one with the calendar dates then you interval match the date field to the start and end field and from there it will work the last join is just to tidy up a bit.
The result of all of that is this ctrl-t. Don't worry about the Syn key it is required to maintain the interval matching.
Then you can have something like this.
Derrick Rose is also excluded since he had not started by 1/1/2004

Crystal Report Date Range Report

i'm using Crystal Reports and I have an output like this (group by day):
(This output calculation is from 00:00 to 23:59 each day..)
Date (dd/mm/yyyy) Weight
-----------------------------------------
01-01-2013 4000
02-01-2013 3000
03-01-2013 6000
04-01-2013 5000
How can I make it by time range like 01-01-2013 6:00AM to 04-01-2013 6:00AM and the output still as per day:
(I pretend the half of current day + half of the next day)
Date (dd/mm/yyyy) Weight
-----------------------------------------
01-01-2013 3500 ( =half of 01-01-2013 and 02-01-2013)
02-01-2013 4500 ( =half of 02-01-2013 and 03-01-2013)
03-01-2013 5500 ( =half of 03-01-2013 and 04-01-2013)
04-01-2013 2500 ( =half of 04-01-2013 and so on..)
Thanks,
You'd want to check the time whether it's before or after 12:00 noon. If it's 11:59:59 or less, add it to the previous day. Anything after, current day. Create a formula using something like this
IF TIME({yourdatetime}) <= TIME(11,59,59) THEN
DATE({yourdatetime}) - 1
ELSE
DATE({yourdatetime})
Then group by the formula and format the group header for just the date.

SSRS - Retrieve previous of first field outside selected data

I have an SQL table that contains 4 columns
1) ID
2) EquipmentID
3) Date
4) Hours e.g. 10000
I have an SSRS report that displays the contents of this table
A from and to date parameter is used to select a date range of records
The table is grouped by equipment
In the equipment group I have added a row below with the following expression in the hours column
Last(Fields!Hours.Value) - First(Fields!Hours.Value) = "Total actual hours used"
e.g. 10000 - 9500 = 500
This is does not return the correct "Total actual hours used"
The expression is incorrect
It should actaully be...
Last(Fields!Hours.Value) - PREVIOUS(First(Fields!Hours.Value)) = "Total actual hours used"
e.g. 10000 - 9450 = 550
My issue is how can I get PREVIOUS(First(Fields!Hours.Value)?
By selecting the parameter date range I do not retrieve PREVIOUS(First(Fields!Hours.Value)
Thanks!
To get the expected result for your report expression i.e. Last(Fields!Hours.Value) - First(Fields!Hours.Value), an appropriate Order BY FieldName clause should be implemented in your T-Sql/SP.
Thanks for the tip Aftab
The SQL is already ordered by the date
Perhaps an example of the table would give you better understanding of why I need PREVIOUS(First(Fields!Hours.Value)
Date: 2012-09-01 Hours = 9500 (This is the total hours recorded at the end of the day and is used as the starting hours for the next day)
...
Date: 2012-09-30 Hours = 10000
Therefore if I use the expression...
Last(Fields!Hours.Value) - First(Fields!Hours.Value) = "Total actual hours used" e.g. 10000 - 9500 = 500
This returns the "Total actual hours used" of 500 for the from 2012-09-02 to 2012-09-30
I need the PREVIOUS(First(Fields!Hours.Value) to calculate the correct "Total actual hours used" from 2012-09-01 to 2012-09-30