Willie Doyle
08/28/2023, 4:35 PMIvana Gasparekova
08/28/2023, 4:44 PMIvana Gasparekova
08/28/2023, 4:48 PMWillie Doyle
08/28/2023, 4:54 PMWillie Doyle
08/28/2023, 4:57 PMWillie Doyle
08/28/2023, 5:00 PMIvana Gasparekova
08/28/2023, 5:31 PMWillie Doyle
08/28/2023, 8:33 PMWillie Doyle
08/28/2023, 8:34 PMIvana Gasparekova
08/29/2023, 2:27 PMMichal HauzĂrek
08/29/2023, 7:06 PMSELECT MIN(price) WHERE (
SELECT RANK(
(SELECT Date (Order Date) BY Records of Order Line Item)
) ASC WITHIN (Order Line SKU, ALL OTHER) ) = 1
`last_sku_price`:
SELECT MIN(price) WHERE (
SELECT RANK(
(SELECT Date (Order Date) BY Records of Order Line Item)
) DESC WITHIN (Order Line SKU, ALL OTHER) ) = 1
Differences from your original approach is:
• ALL OTHER
in the WITHIN clause (to lock the rank calculation only by SKU and nothing else, no matter what dimensionality the KPI/insight or higher-level metric uses
• sub-metric with (SELECT date BY primary key)
instead of just plain date
in the RANK function. This is due to the fact that date dimension in GoodData is special and treated as a separate dataset which can be referenced from multiple other datasets (those where the date values actually are). It is a little counter-intuitive, but this is the way how to say “Use the values of date from this dataset”. (and you need to do it even if there is currently only one dataset connected to it).
Calculating the average price drift
Then with these two metrics prepared, you can use them in another metric:
SELECT AVG (
( SELECT last_sku_price - first_sku_price BY Order Line SKU, ALL OTHER )
)
Here we are calculating average of the difference of those two metrics. The expression BY Order Line SKU, ALL OTHER
again forces the difference to be calculated on the SKU level (no matter what the report/kpi/metric context is).
On top of that we are applying AVG so this metric will also work as a KPI, giving you the average price drift across all SKUs (unweighted).
You can use this same metric both for your KPI (or headline insight to enable drill on it) and for your detailed report/insight viewed by SKU.
Attached please see the results on some sample data.
I hope this helps.Willie Doyle
08/29/2023, 7:47 PMMichal HauzĂrek
08/29/2023, 7:54 PMBY
and then you need to select an attribute (representing the dataset) from the list. It is an attribute which is in the data model a primary key of your Order Line Item
dataset.
That is either:
• If you have single-attribute primary key (i.e. Order Line Item ID
) you select that one.
• Or if you do not have single-attribute primary key (either have compound primary key from multiple attributes/references or no primary key at all) GoodData automatically created a pseudo-attribute called Records of (name of dataset)
for you. And you select that one (it will be in the list).Willie Doyle
08/30/2023, 12:49 AMWillie Doyle
08/30/2023, 1:04 AMWillie Doyle
08/30/2023, 2:31 AMMichal HauzĂrek
08/30/2023, 10:32 AMSELECT SUM(x) BY Customer
and use this in an insight with Customer
and Product
attributes in it, it automatically calculates it as if it was BY Customer, Product
(only if this combination is compatible from the data model perspective). If you have SELECT SUM(x) BY Customer, ALL OTHER
it will behave differently - if you view this metric by Customer
and Product
, it will only break it by Customer and it will repeat the same values (calculated by each Customer
) for different values of Product
for that particular customer.
And it does this not just for LDM-compatible attributes, but for any attribute. So if the metric has BY ALL OTHER in it, it can be used also with unrelated attributes from other part of the model (and you get the total number repeated for all their values).
So I would recommend only using the ALL OTHER when you want to exactly lock the dimension calculation of a metric and make sure it does not change based on which attributes the metric is used with. For sure not in every metric “just in case”. The same is also for the simple BY - use only when needed.
removing ALL OTHER in this case to allow slicing by other attributes
So answer to
And If I actually wanted the price drift to change/update based on other attributes of product that might included in the insight from the product dimension, I should remove the “, ALL OTHER” ?is YES. Same as if you want to see it by date (i.e. difference of first and last SKU price within each month) - see the screenshot, here I removed the ALL OTHER and am now able to view it by month. How filters work with all this Yes, report and dashboard filters (including date filters) are still applied to the calculation (actually to all its parts). The
BY
and BY ALL OTHER
have no impact to the filters actually (similarly how in SQL the WHERE section still applies to GROUP BY). If you want to affect what filters are or are not applied to a metric, you can use another concept for overriding parent filters:
• WITHOUT PARENT FILTER
(or WITHOUT PF
for short) makes the metric ignore any filter
• WITH PF EXCEPT …
makes it ignore only the explicitly named ones
• WITHOUT PF EXCEPT …
ignores all filters but the explicitly named ones
And you can combine this with BY / BY ALL
So for example a metric SELECT MAX(price) BY ALL OTHER WITHOUT PF
gives you a global maximal price (across all SKUs, all orders, all suppliers, all time - no matter what filters you use and with what attributes in the report). And it will give you the same number for any value of any attribute…Willie Doyle
08/30/2023, 2:48 PMWillie Doyle
08/30/2023, 8:03 PMMichal HauzĂrek
08/30/2023, 9:09 PMMichal HauzĂrek
08/30/2023, 9:29 PMCOUNT (Order ID)
.
I assume in your data model (similarly to mine), the Order ID
is a primary key in Orders
and foreign key in Order Line Items
, right?
Well for GoodData these are just two places where the attribute Order ID
can be counted (in Orders
and in Order Line Items
) with potentially different results and different granularity of the result.
If the function COUNT in GoodData is used with just one parameter, it tries to be “smart” and guess which of these you want to actually count based on the context. I am not sure if the filter warning works with this guessing and full context. Especially if you have the date connected to line items, it would mean that one of these counts would be filterable by the date and the other would not (from the GoodData model perspective).
Personally I usually do not want my COUNT metric to switch where they are counted depending on how they are used, so I prefer the two-parametric COUNT (where the second parameter is primary key attribute which explicitly defines the dataset where to count). I am not sure if in your case this matters result-wise (i.e. if there are any orders without line items) but in some cases it can be significantly different (i.e. count of existing teams vs count of teams with assigned task). So I would recommend trying to switch to two-parametric count and see if the warning is still there.Willie Doyle
08/31/2023, 5:07 PMMichal HauzĂrek
08/31/2023, 7:55 PM