Calculated Field in Tableau Count Distinct with Condition - tableau-api

I'm trying to calculate the distinct number of IP Addresses in Tableau where the Year is 2020.
How can I do this in Tableau?
I've tried this..but it's not giving the right result:
{FIXED [IP] : SUM(IIF[Year] = 2020,1,0))}

You can use the built in COUNTD() function.
COUNTD(IF [YEAR] = 2020 THEN [IP] END)

IF DATETRUNC('month', [Created Date])=DATETRUNC('month',[PERFORMANCE_DATE])
THEN
COUNT([Slug Title])*31/28
ELSEIF DATETRUNC('month', [Created Date])< DATETRUNC('month',[PERFORMANCE_DATE])
THEN COUNT([Slug Title])
END
im trying to display is above condition is true then COUNT([Slug Title])*31/28 and if its false then only COUNT([Slug Title])
please resolve my above queries

Related

Tableau Calculated Field of Running Average for the last month

Hey Guys I am trying to do a calculation for a Running Average over the last month in a calculated field in Tableau. However I struggle with defining the last month range and adding it to the calculation. I thought of using
IF [date] >= DATEADD('month', -1, TODAY()) THEN
RUNNING_AVG(SUM( IF [Entry Type] = 'Sale'
THEN [Invoiced Quantity]
ELSE 0
END )) END
However this is not working at all. I hope someone can help me out. Cheers
This worked out:
(SUM( IF [Entry Type] = 'Sale' AND [Posting Date] >= DATEADD('month',-1,TODAY())
THEN [Invoiced Quantity]
ELSE 0
END
))
You do not have to write this into calculated field. Just filter date column and set that to be always filter for last 30 days, or last month. Then, use "calculated field" section just for calculation independently from the "date" which is already considered in filter section.
Good luck

How to dynamically calculate the YTD for current year without using a table calculation in Tableau?

How do I dynamically calculate the Year To Date (YTD) for the current year without using a table calculation in Tableau?
I have used the below formulas to calculate YoY for the current year:
if datediff('year',[Date],TODAY())=0 then [Sales] END
For the previous year:
if datediff('year',[Date],TODAY())=1 then [Sales] END
YoY:
sum(current year)/sum(previous year)-1
create a calculated field:
[date] >= MAKEDATE(Year(today()),1,1) and
[date]<= today()
Drag this to filter and select True
It depends on what you're trying to achieve. If you want to filter dates to show only values in the current year without a table calculation, then you could create a calculated field like below and filter on the result:
if Year([Date]) = YEAR(TODAY()) then "YTD" else "Not" END

Create a measure to return the maximum date about the order in a fact table. (SSAS Multidimensional)

I want to create a measure which return the maximum date about Orders but before the actual day
I will write an example :
My tables here
(In my table Calendar i have the year 2016,2017,2019, and in my Order table, i have an order for 2016 and 2019,
I want the last date order but before the actual day (18/05/2017), so i want the Date 01/01/2016).
I have 2 table, a dimension Calendar and a fact table Order.
I was thinking about the function filter, so i search how to use filter in
google, and all the solutions i found use 'With' and 'Select'.
(I can't use 'With' and 'Select' when i create a measure in SSAS multidimensional).
Hope i will see your advice.
Just like this similar case in adv cube?
[max order date] return the maximum date about [Internet Sales Amount]
with member [max order date] AS
tail(NONEMPTY([Date].[Date].[Date],[Measures].[Internet Sales Amount])).item(0).item(0).PROPERTIES( "name" )
select {[max order date] } on 0 from [Adventure Works]
if yes, then you can create a measure in your cube like this:
Create Member CurrentCube.[Measures].[max order date]
As tail(NONEMPTY([Date].[Date].[Date],[Measures].[Internet Sales
Amount])).item(0).item(0).PROPERTIES( "name" );
if only till current day, then(following is refer to adv cube, you need do some code changes per your cube):
Create Member CurrentCube.[max order date] AS
Tail
(
NonEmpty
(
{
Head([Date].[Date].[Date]).Item(0).Item(0)--the first day in your Date dim
:
StrToMember("[Date].[Date].&[" + Format(Now(),"yyyyMMdd") + "]")-- as of current day
}
,[Measures].[Internet Sales Amount]
)
).Item(0).Item(0).Properties("name")
IDE to Write, Analyze, Tuning, Debug MDX efficiently (www.mdx-helper.com)

Using a single Calculated field , can I get the number of weekdays calculated from the current month in Tableau?

I have a requirement to do % of (Workdays till date) / (Total Workdays of the month). How can I create a "Calculated field" for this logic. I don't need to consider holidays or any sort. Any help is highly appreciated.
A quick google search turned up this:
http://kb.tableau.com/articles/knowledgebase/calculating-the-number-of-business-days
In the Calculated Field dialog box, do the following and then click
OK: Name the calculated field. In the example workbook, the calculated
field is named Number of Weekdays. In the formula field, create a
calculated field similar to the following:
DATEDIFF("weekday", [Start Date], [End Date])
- 2 * (DATEPART('week', [End Date]) -DATEPART('week', [Start Date]))
+ (IF DATENAME('weekday',[End Date]) = 'Saturday' OR DATENAME('weekday',[Start Date]) = 'Sunday'
THEN 0 ELSE 1 END)
In your example you take the difference between the first and the last of a month and calculate the working days by subtracting 2 * [number of weeks] for the weekends. Once you have that value you can easily create the ratio you wanted.

Tableau: Aggregate and Non-aggregate error with Date calculations

I'm having trouble with a calculation in tableau. I've created some calculations that are listed at the top that I use in the calculation I'm currently working on.
Last 30 days calc:
IF [Date] < (today() - 31) OR [Date] > today()
THEN NULL ELSE [Date] END
Price-AvgWeighted calc:
SUM ([SaleTotal]) / SUM([Qty])
Calculation with ERROR:
IF NOT (ISNULL([Last30days])) AND [Rev]>500 AND QTY > 10 AND [Price] < (.7*([Price-AvgWeighted]))
THEN 'True'
ELSE 'False'
END
ERROR: cannot mix aggregate and non-aggregate arguments with this function. (Highlights the "<")
My goal is to create a calculation that does the following:
"If in the last 30 days revenue is greater than 500 and qty is greater than 10 for all previous sold and the current (available) price is less than .7 of the last 30 day weighted average sales price THEN True/false"
I'm also not sure how to incorporate the Status Dimension (shows type of product: sold/avil)
Any help would be greatly appreciated. Thanks
It looks like you have to turn [Last30days], [Rev], [QTY] and [Price] into aggregations since [Price-AvgWeighted] is an aggregation.
Try the following:
IF NOT (ISNULL(ATTR([Last30days]))) AND SUM([Rev])>500 AND SUM([QTY]) > 10 AND SUM([Price]) < (.7*([Price-AvgWeighted])) THEN 'True' ELSE 'False' END