
Semi additive measures / Omni Dimensionlize (about to launch)
Semi additive measures. Working with data that doesn't aggregate over time (MAUs, credit balances, etc) can be painful. Now we have native operators that can handle all that nuance with…
Transcript
This transcript is auto-generated. Names and product terms may be wrong.
uh second demo is this semi additive concept um which uh it's kind of a new one for me I have to admit uh so the the demo here is Right a so this idea of semi additive measures is if you have some attribute in your table that is some kind of running total or some kind of cumulative thing over time that makes sense to add up across everything else except for time so you say like so in this case I've got this fake random data basically that's like that's imagining that users all started out with some balance and then are spending down the balance slowly and this is a daily table it's got every day and a user and it's got their balance beginning of
the day um and so it makes sense to add up the balance across users but if you add up the balance across days in a week you're going to get the wrong answer because you're going to basically add up duplicative uh you're going to double count so show that over here right this is just if I just group If I Do by month and just sum the balance these are just I mean it's all garbage numbers it's random data but these are especially garbage numbers they're wildly wrong like that it should always be going down because they they started out with a random number just been spending it down and this is fluctuating all over the place clearly the wrong uh wrong answer so if
we go here we get the right answer with these ending balance sum and starting balance sum measures and so what are they um they're a sum with a filter measure that we I don't know what's going on there but oh I hit it that's a funny bug an I hit it since our demo and now it doesn't show up very well here oh well there's a field here um let if you search for it in the field picker you can unhide it for the St oh Fair well I'm already here now uh oh here it is these don't mind me all right so back to that um what are these def find do so it's this is last date field is true so it's this
filter measure is last date field is true nothing new about that what's is last date nothing simp it's just some field last date is equal to the date that's what I can name this daily the daily field uh so how's that defined so that has this uh which is this funny thing that we just made this up and may not be the final form of this but it's special Omni operator uh that does omni magic and allows this to work because basically what you're saying is I want to take the max of the date within the grouping right so it's grouped by month and I want to take the the max of the date uh within the month and uh which is sensible to do
like it's easy to think about it's not complicated but just in SQL I doesn't work very well because you're trying to like take an Aggregate and then use that aggregate of the max is a filter for another aggregate so uh it and the sequel is really crazy because it's already got my crazy random Generation stuff in it but the core thing is that somewhere in here there's a join that is basically it takes the query to get the max Group by month then join that value back in and uses it in the main query wherever it went over here basically do the filtered measure uh and it what's nice about it is because it's all just SQL and it's all part of our relation algebra
SQL stack it basically I mean there were a couple tweaks needed but it works with all the other stuff let me make this bigger so like here it is subt so like sub TOS are on right and we're rolling up by quarter and year and the the balances are what you would expect like end of your balance didn't put the actual total on but the total the total would be the final balance um and the beginning balance so yeah it pivots all the right and all just like folds together so uh what how did you guys come up with the name om dimensionalized what does that mean oh so yeah so that's the that's is like there's no semi additive measures in the kind of
thing I implemented it just means basically take some expression that might have aggregate functions in it and go shove it off into another query where I run it in the context of the of the main queries grouping so that basically have this Dynamic grouping you so yeah do does that effectively mean that you could do essentially like on the-fly customer facts yeah you can do onfly fact yeah this is is that's create a dimension that's like lifetime spend and you could essentially make that a dimension on the user is that true Jamie's probably better able to answer that all asking these same questions last show all I kept saying is all it takes an Aggregate and it moves it over and runs it in the
grouping and then puts it back and it OB the grouping of the output query so I think it might do the opposite of what we want on facts potentially not sure we'll have to play with it okay the naming is definitely a little funky but yeah obviously the function is epic a possibility considered is to just forget the Omni operator entirely and basically allow you to define a dimension with some SQL and you can put aggregate functions in the SQL and then some kind of parameter Force dimensionalize or something that basically says like I want you to take this Dimension and do this thing with it but it's magic and super exciting thank you under the hood this isn't doing anything special in terms of
the SQL itself it's just telling us where we're allowed to use it is that the right way to think about it no it's doing something special it's it's forcing this it's forcing this join basically it's like splitting the query into this part that is in this wrapped in this Omni dimensionalized thing running it in a second kind of subquery and joining that subquery back in yeah sort of like a a virtual view for this one dimension uh that's being joined back in given given the sort of the the state of the first query yeah uh uh the the partner who were were considering implementing this form working with this customer what they had done was use looker inquiry to accomplish something similar where basically they
had a CTE View and looker and they used inquiry to dynamically changeed the grouping of that CTE and then join it back in um but that's uh obviously it's brittle complicated you have to understand in query and doesn't doesn't generalize you have to write in every single thing that you want Stephen if if we wanted to could we take these sort of or I guess what is the philosophy around taking these lower level things and putting something on a measure that just says semi additives over X and essentially does all this behind the scenes it would I would I would need to as long as it was simple there's nothing uh wrong with it philosophically it would just need to be simple enough like it
you couldn't just be somebody out of true like that doesn't mean you would need to have no no exactly you'd have to you'd have to reference it to a field but then implicitly like the field would take a Max or a Min of usually a Time Field grab one of them because like 99% of the time these are going to be date like essentially men's or Max over date periods of a subgrouping of that date period And I feel like if you could just sort of say like daily active users like whatever is daily monthly active user same deal like you pick the start of the end yeah them on um yeah what I think it makes sense to to find something ergonomic so what
what we might do is just land it even with this Omni dimensional I thing because under the hood that's what it's always going to look like like in the core and then like that's the totally unergonomic way to get it we can play with it unblock some use cases and then think about like what's the best way to really bubble it up we're like slowly building a Dax language it's kind of amusing I I've personally written the squel to do this exact analysis that you demoed um for my previous company uh this would have saved me quite a lot of time so that's because the inverse of this is to run it outside the group ey that's actually like the lifetime that's the lifetime orders
type thing and it's sort of like an ignore group ey so this one is like a take a measure and shove it in the group ey and dimensionalize it and the other one is do something before the group ey dimensionalize it and then do it but like it might be worth just sitting down and doing like an hour of looking at all the concepts that exists in Dex because they've just formed to solve all these types of problems and just making sure or like thinking about whether we care about those problems and sort of like what the types of things that we need are not that we need them all right now but they're all created to do this kind of stuff exactly