What is your full calculation? You need an end after an if statement.
Thanks for your response. I believe you're referring to the C# code I posted? (I'm aware this won't work in a tableau calculated field but I'm simply using it to illustrate what I'm trying to achieve)
If you are referring to the C# code then what I have typed above is syntactically valid, it might be a little clearer expressed as follows however:
if (DateOfBirth.Value.Date > now.AddYears(-age))
I'm trying to perform the same calculation in Tableau as I have in the C# code. (Sorry if that isn't very helpful but C# is my preferred language and I found it the most concise way to express my intended calculation)
My intended full calculation will take a date of birth and return the persons age in years
3 of 3 people found this helpful
Will something like the below work? It appears to work on my side in Tableau, but I didn't test specifically for a leap year case. This would be for the Age calculation to reproduce, at least logically, what you have in c# code above.
IF [DOB]>DATEADD('year',-DATEDIFF('year',[DOB],TODAY()),TODAY()) THEN
Thanks very much. This has worked perfectly! You've saved me a lot of head scratching!
What would need to be done to calculate age based on a fixed day? Suppose one is doing historical reporting, using TODAY() would not be accurate.
Can a mm/dd/yyyy be substituted for TODAY ()?
1 of 1 people found this helpful
To get Age based on a given Reporting Date use the following:
IF [DoB] > DATEADD('year',-DATEDIFF('year',[DoB],[Reporting Date]),[Reporting Date]) THEN
In your case [Reporting Date] could be a calculated field with DateParse, e.g. DATEPARSE("mm/dd/yyyy","10/04/2016"), or parameter driven using MAKEDATE([Year],[Month],[Day]).