I have 3 dimensions :
Dim_Account
Dim_AccountAccountGroup(The bridge table)
Dim_AccountGroup
Account and AccountGroup have a many_to_many relationship.
I have a measure named ENG onachievedvalue
it's the sum(onachievedvalue) from Sales_Objectives fact_table.
The problem is :
When I display the measure only by Account_code(from dim_account), it works
[measure by Account_code(from dim_account)][1]
When I display the measure only by Group_code(from dim_accountGroup), it works
[measure by Group_code][2]
But when I want to display the measure by Account_code and Group_code, I get the problem of "Unknown" values. When I have value in account_code the group_code is unknown and vice versa.
[Unknown values when using both dimensions][3]
When using account_code and group_code with another simple measure from the account table, It works :
[Display another measure by account and group code][4]
Why do I get this Unknown values when the account is linked to the accountGroup. I checked in the Database I have groups for each account...
[1]: https://i.stack.imgur.com/JKsT7.png
[2]: https://i.stack.imgur.com/QJzFl.png
[3]: https://i.stack.imgur.com/5YTh2.png
[4]: https://i.stack.imgur.com/BGfFN.png
Related
Consider a table in Google BigQuery containing purchase records for customer. For the sake of simplicity, let's focus on the following properties:
customer_id, product_id, amount
I'd like to create a Google Data Studio report from the above data set showing a customer lifetime value histogram. The customer lifetime value is the sum of amount for any given customer. The histogram would show how many customers fall into a certain bucket by their total amount - I would define the buckets like 0-10, 10-20, 20-30 etc. value ranges.
Like this:
Finally, I'd also like to filter the histogram by product_id. When the filter is active, the histogram would show the totals for customers who - at least once - purchased the given product.
As of this moment, I think this is not possible to implement in Datastudio, but I hope I am wrong.
Things I've tried so far:
Displaying an average customer lifetime value for the whole dataset is easy, via a calculated field in Datastudio as SUM(amount) / COUNT(customer_id)
For creating a histogram, I don't see any way purely in Data Studio (based on the above data set). I think I need to create a view of the original table, consisting a single row for each customer with the total amount. The bucket assignment could be implemented either in Big Query or in Data Studio with CASE ... WHEN.
However, for the final step, i.e. creating a product filter that filters the histogram for those customers who purchased the given product, I have no clue how to approach this.
Any thoughts?
I was able to do a similar reproduction to what you describe but it's not straightforward so I'll try to detail everything. The main idea is to have two data sources from the same table: one contains customer_id and product_id so that we can filter it while the other one contains customer_id and the already calculated amount_bucket field. This way we can join it (blend data) on customer_id and filter according to product_id which won't change the amount_bucket calculations.
I used the following script to create some data in BigQuery:
CREATE OR REPLACE TABLE data_studio.histogram
(
customer_id STRING,
product_id STRING,
amount INT64
);
INSERT INTO data_studio.histogram (customer_id, product_id, amount)
VALUES ('John', 'Game', 60),
('John', 'TV', 800),
('John', 'Console', 300),
('Paul', 'Sofa', 1200),
('George', 'TV', 750),
('Ringo', 'Movie', 20),
('Ringo', 'Console', 250)
;
Then I connect directly to the BigQuery table and get the following fields. Data source is called histogram:
We add our second data source (BigQuery) using a custom query:
SELECT
customer_id,
CASE
WHEN SUM(amount) < 500 THEN '0-500'
WHEN SUM(amount) < 1000 THEN '500-1000'
WHEN SUM(amount) < 1500 THEN '1000-1500'
ELSE '1500+'
END
AS amount_bucket
FROM
data_studio.histogram
GROUP BY
customer_id
With only the latter we could already do a basic histogram with the following configuration:
Dimension is amount_bucket, metric is Record count. I made a bucket_order custom field to sort it as lexicographically '1000-1500' comes before '500-1000':
CASE
WHEN amount_bucket = '0-500' THEN 0
WHEN amount_bucket = '500-1000' THEN 1
WHEN amount_bucket = '1000-1500' THEN 2
ELSE 3
END
Now we add the product_id filter on top and a new chart with the following configuration:
Note that metric is CTD (Count Distinct) of customer_id and the Blended data data source is implemented as:
An example where I filter by TV so only George and John appear but the other products are still counted for the total amount calculation:
I hope it works for you.
I have a multi-dimensional cube that has multiple rows for each shop. There is a ShopCount measure that is a DistinctCount over the ShopKey field in the cube, which is in another measure group. I can get Shop counts over all sorts of different dimensions, which in this case is usually location. That works fine.
Now I want a variant of this. I want an inline distinct count of shops based on another measure or dimension.
Here is an example mdx that gives me a distinct count of shops for a particular month, where the shop type is either automotive or camping.
SELECT [Measures].[Shop Count] ON COLUMNS
FROM [Retail Cube]
WHERE ([Report Date].[Month].[201905],
{[Shop].[ShopType].&[Automotive],[Shop].[ShopType].&[Camping]})
CELL PROPERTIES VALUE
In Excel, I would like to be able to get another column that has the distinct count of Automotive and Camping shops over the range of months in my database. I would like to then be able to filter the columns by all the existing dimensions that I am currently filtering by.
I tried creating a calculated field in the Calculations tab, such as:
COUNT(DISTINCT CASE WHEN [Shop].[ShopType].&[Automotive] THEN [Shop].[Shop Key]
WHEN [Shop].[ShopType].&[Camping] THEN [Shop].[Shop Key]
ELSE NULL END)
(Note: Shop Key is what I do my Distinct Count over)
After substantial processing it came up with an error in that column.
How can I achieve what I am trying to do?
In my product dimension, I have an attribute called CustomerRating which is a string. Possible values are "1", "2", "3", and "4".
I want to turn this attribute into a Measure that averages ratings for collections of products.
with member [Measures].[Product Rating] as
( [Product].[Project Name].CurrentMember.Properties("CustomerRating"))
select [Measures].[Product Rating] on columns
from [MyCube]
This query produces an error - I suspect because I'm dealing with a string.
How do I turn customer rating into a measure that is an average rather than a sum?
The best approach would be to add an int column to the source table of the dimension, maybe just as a named calculation in the DSV. Then you would add a measure group on the dimension table, and define a measure rating_sum that sums this column, and a count measure in this measure group.
Then define a calculated measure as rating_sum / count.
If everything works, make the two measures rating_sum and count invisible.
Not tested but I'm wondering if this errors?
WITH
MEMBER [Measures].[Product Rating] AS
CInt([Product].[Project Name].CurrentMember.Properties("CustomerRating"))
SELECT
{[Measures].[Product Rating]} ON COLUMNS
From [MyCube]
I'm not very experienced in OLAP Cube + MDX, and I'm having a hard time trying to use twice the same measure in a cube.
Let's say that we have 3 Dimensions: D_DATE, D_USER, D_TYPE_OF_SALE_TARGET and 3 tables of Fact: F_SALE, F_MEETING, F_SALE_TARGET
F_SALE is linked to D_USER (who make the sale) and D_DATE (when)
F_SALE_TARGET is linked to D_USER, D_DATE, D_TYPE_OF_SALE_TARGET (meaning: user has to reach various goals/targets for a given month).
I can browse my cube:
Rows = Date * User
Cols = Number of sale, Total amount of sale + the value of 1 target (in the WHERE clause, I filter on [Dim TYPE SALE TARGET].[Code].&[code.numberOfSales])
How can I add other columns for other targets? As all the targets are in the same table, I don't see how to add a second measure from [Measures].[Value - F_SALE_TARGET] linked to a different code, ie. [Dim TYPE SALE TARGET].[Code].&[code.amountOfSale].
your question is not clear to me but it seems like one way to accomplish that is by creating Calculated Members. Basically, select you cube in BIDS, go to the Calculations tab and create Calculated Members. You would be able to insert your MDX query there. For each target type you can create a different calculation such as: ([Measures].[Value - F_SALE_TARGET], [Dim TYPE SALE TARGET].[Code].&[code.amountOfSale])
Say I have a measure, foo, in a cube, and I have a reporting requirement that users want to see the following measures in a report:
total foo
total foo excluding instances where foo > 10
total foo excluding instances where foo > 30
What is the best way to handle this?
In the past, I have added Named Calculations which return NULL if foo > 10 or just foo otherwise.
I feel like there has to be a way to accomplish this in MDX (something like Filter([Measures].[foo], [Measures].[foo] > 10)), but I can't for the life of me figure anything out.
Any ideas?
The trick is that you need to apply the filter on your set, not on your measure.
For example, using the usual Microsoft 'warehouse and sales' demo cube, the following MDX will display the sales for all the stores where sales were greater than $2000.
SELECT Filter([Store].[Stores].[Store].members, [Unit Sales] > 2000) ON COLUMNS,
[Unit Sales] ON ROWS
FROM [Warehouse and Sales]
I met similar problem when use saiku (backend with Mondrain), as I haven't found any clear solution of "add filter on measure", I added it here, and that may be useful for other guy.
In Saiku3.8, you could add filter on UI: "column"->"filter"->"custom", then you may see a Filter MDX Expression.
Let's suppose we want clicks in Ad greater than 1000, then add the following line there:
[Measures].[clicks] > 1000
Save and close, then that filter will be valid for find elem with clicks greater than 1000.
The MDX likes below (suppose dt as dimension and clicks as measure, we want to find dt with clicks more than 1000)
WITH
SET [~ROWS] AS
Filter({[Dt].[dt].[dt].Members}, ([Measures].[clicks] > 1000))
SELECT
NON EMPTY {[Measures].[clicks]} ON COLUMNS,
NON EMPTY [~ROWS] ON ROWS
FROM [OfflineData]
i think you have two choices:
1- Add column to your fact(or view on data source view that is based on fact table)like:
case when unit_Price>2000 then 1
else 0
end as Unit_Price_Uper_Or_Under_10
and add a fictitious Dimension based on this columns value.
and add named query for New Dimension(say Range_Dimension in datasourceview :
select 1 as range
union all
select 0 as range
and after taht you cant used this filter like other dimension and attribute.
SELECT [Store].[Stores].[Store].members ON COLUMNS,
[Unit Sales] ON ROWS
FROM [Warehouse and Sales]
WHERE [Test_Dimension].[Range].&[1]
the problem is for every range you must add When condition and only if the range is static this solution is a good solution.
and for dynamic range it's better to formulate the range (based on disceretizing method )
2- add dimension with granularity near fact table based on fact table
for example if we have fact table with primary key Sale_id.we can add
dimension based on fact table with only one column sale_Id and in dimension Usage tab
we can relate this new dimension and measure group with relation type Fact and
after that in mdx we can use something like :
filter([dim Sale].[Sale Id].[Sale Id].members,[Measures].[Unit Price]>2000)