tableau - Aggregate by most recent not-null value -


i have dataset following columns [ product_id, country_id, date, number_of_installs, cumulative_installs_last_30_days ]

i have no problem applying standard measures find sum, max or average number_of_installs within 3 dimensions (product_id, country_id, date(aggregated month or week)). however, have not been able aggregate cumulative_installs_last_30_days because variable cumulative, need return “most recent value” , tableau not have option built-in aggregation functions.

how create calculated field enables addicional column in aggregated dataset recent not-null value of cumulativeinstalls_last_30_days within dimensions product_id, country_id , date(aggregated month or week)?

here's dirty solution.

in comments, noted wanted 30 days dynamic, accomplish that, create parameter, make integer, select range, , allow integer on zero. i'll call [number of days].

then create calculated field:

total(sum(iif(datediff("day", [date], today()) < [number of days], [number of installs], null))) 

i know that's ridonk, i'll break down, inside out.

datediff("day", [date], today()) 

that calculates difference in days between today , date in given row.

iif(datediff("day", [date], today()) < [number of days], [number of installs], null) 

that checks if difference less number of days selected. if is, statement equal number of installs. if it's not, it's null. result, if sum of these values, number of installs in last [number of days] days.

with in mind, sum() rows. total() performs sum on every database row contributes partition.

note if database has dates after today(), you'll need add condition iif() statement make sure aren't included.


you mentioned want able aggregate number of installs month. that's easier. toss month([date]) dashboard, sum([number of installs]), , tableau knock out you.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -