Google Data Studio: Creating Ranking Dimension - google-data-studio

I would like to create a ranking dimension in one of the Google Data Studio reports.
The data source for the report is [GSC Site] which has information on [Query] (a dimension) and [Average Ranking] (a metric). Trying to use the CASE formula to create a new field called "Ranking" as follows:
CASE
WHEN Average Position >= 0 AND Average Position <= 5 THEN "Top 5"
WHEN Average Position > 5 AND Average Position <= 10 THEN "Top 10"
ELSE "Not Ranked"
END
and get the message "Only numeric literals are allowed if aggregated fields are used in CASE."
As I understand, the field "Average Ranking" is metric with default aggregation "Auto" which prevents me from using the CASE formula.
What would be a possible solution where a new field is created as (i.e. dimension) with default aggregation "None" and populated with the above-ranking distribution values (Top 5, Top 10 and Not Ranked).

I was trying to do the same thing, and the solution I came up with was to blend GSC data with itself. With a blend, you don't have the same auto-aggregation limitation if you add a custom field to a specific table or chart. Here is what the blend looks like:
Then use the blend as the datasource for your chart, and click to add a dimension and select Create Field. My custom field used a case statement almost identical to the one in your question.

Related

How can I re-categorize any counts < n in Google Data Studio?

I'm creating a dashboard that shows some demographic information for a population. However, in cases where less than 25 individuals show a certain demographic trait, I need to be able to re-categorize that trait as "REDACTED" to protect privacy.
A pseudo-code version might be:
CASE
WHEN COUNT(gender) < 25 THEN "REDACTED"
ELSE gender
END
Unfortunately, this mixes aggregation and non-aggregation and isn't workable in a calculated field.
I'm hoping for some suggestions on how to solve preferably without aggregating first in the data source --I'd like to be for my data and blends to exist at the individual grain with aggregation happening within Google Data Studio.
Publicly-Editable Example Google Data Studio report
Data source (INPUT) is the source, also available here.
Expected output:
gender
count
female
222
male
223
REDACTED
55
0) Summary
The below looks at:
Issue: "calculated fields can't mix metrics (aggregated values) and dimensions (non-aggregated values)"
Suggestion: Reaggregating data using a blend
1) Issue
A system error is displayed:
Sorry, calculated fields can't mix metrics (aggregated values) and dimensions (non-aggregated values). Please check the aggregation types of the fields used in this formula. Learn more.
when using the calculated field in the question:
CASE
WHEN COUNT(gender) < 25 THEN "REDACTED"
ELSE gender
END
This ("aggregated values") refers to the 2nd line in the CASE, specifically the aggregated field:
COUNT(gender)
2) Suggestion
One way is to use reaggregation with a blend, by performing a self blend (where the data source of both tables are the same) and creating a dedicated COUNT(gender) field (titled gender_count below):
2.1) Blend Fields
Table 1
Table 2
Dimension #1: gender
Dimension #1: gender
Dimension #2: person_id
Dimension #3: dept
Metric: Record Count
Metric: gender Aggregation: COUNT Rename: gender_count
2.2) Join Configuration
Join Description
Table 1 🔗 Table 2
Join Operator
Left Outer
Join Condition
gender 🔗 gender
Image
In summary, the result of the blend will look like:
2.3) Pie Chart
Dimension:
CASE
WHEN gender_count < 25 THEN "REDACTED"
ELSE gender
END
Metric: Record Count
Publicly editable Google Data Studio report (embedded Google Sheets data source) and a GIF to elaborate:
Unfortunately Google Data Studio doesn't let you use an aggregate function (SUM, AVG, COUNT) in a CASE statement and return a dimension. However there is a workaround for this. First create a field like this:
field1
CASE
WHEN COUNT(gender) < 25 THEN 1
ELSE 0
END
then create a second one like this
field2
CASE
WHEN field1 = 1 THEN "REDACTED"
ELSE gender
END

Google Data Studio convert metric to dimension not working

I have imported my GA4 data into Google Data Studio and am trying to see how many giftcards have been sold by their value.
The item revenue metric in GA4 is equal to the giftcard value (i.e. revenue = $200 therefore $200 giftcard was sold).
I want to breakdown sales by giftcard value like so:
Giftcard (revenue)
Count
$200
4
$250
3
$300
6
To do this, I need to set a copy of item revenue as a dimension rather than a metric.
In Google Data Studio, I can create a calculated field with the following formula that should convert the item revenue into text:
CAST(Item Revenue AS TEXT)
The problem I'm having is that while the formula sets the field type as text, it is still regarded by GDS as a metric and can't be used as a dimension.
Even when I try to add text, GDS still recognises the field as a number:
CONCAT(CAST(Item Revenue AS TEXT), " giftcard")
To use a metric as a dimension you can make a combination of data. When defining the graphic element (table, for example) and the respective data source, just create a data combination, but do not combine the data with any other source and just define the combination with the initial data itself. So you will have the same data structure only through a combined structure.
When making a combination of data, data studio recognizes all calculated fields (metrics) as dimensions. Thus, it is possible to make the conversion.

Power BI - Show all data from table1 in a visual from two many to many related tables when one other field from table2 on the X-axis

I have a key column in two many to many related table and sample representation of data is -
(attaching sample version of the table to get the point across as there are other numerous columns not contributing to this visual)
table 1 -
table 2 -
I am making a line graph with date on x axis and the value1 and value 2 on y-axis. The value1 is true for all dates. It is basically a standard target value. Now I want all the value1 summed up to show in my visual as value1 and not just the ones for which I have data on those dates. To explain it better I want 1717 on the graph as well like the total in the table in the following image -
visual -
Is there a way to do this in power BI? I tried to make a shared dimension of all unique key as a separate table and connecting both the tables to that table but there is no change in visual due to that.
You can follow these below steps to achieve your required output-
Step-1 Create a custom column in your *table 1 as below-
value_1_sum =
CALCULATE(
SUM(table_2[value1]),
ALL(table_2)
)
Step-2 Configure your line chart as below. Remember, the aggregation for new custom column will be Average as shown in the image
And here below is the final output-
Additional Reference Here below is list of options you will get after right click on the measure name-

SSRS Conditional Expression

In SSRS report, I want to perform conditional color formatting where highest rank should be Green and lowest rank should be Red within a Regional Manager group as shown below
Note: Couple of options, I was thinking of includes
I am using custom code function, for deriving Min and Max value, and somehow if I can include grouping filter on Regional Manger then it could work, but don't know if that's possible
In dataset, I create extra columns for each column and store Min\max value in it. But less keen towards this option, since I have 24 different ranks and which would mean, I will need 24 different columns along with current 40 attributes
Any help would be appreciated
I know you don't want to do this for each column, but despite your misgivings it is probably the best approach. Based on my previous answer to your earlier related question you can colour the min and max for each group as follows.
Create a table with fields store, atvrank, and btvrank
Right click the row header, and select Add Group -> Row Group - Parent Group, and choose Regional Manager. Set the Group name to RegionalManagerGroup
Then set the background colour for your cells to
=iif(Fields!atvRank.Value = min(Fields!atvRank.Value, "RegionalManagerGroup"),
"Green",
iif(Fields!atvRank.Value = max(Fields!atvRank.Value, "RegionalManagerGroup"),
"Red",
"White"
)
)
This now finds the maximum and minimum within the current group instead of the whole dataset. You will need to set this expression for each field individually, but this is probably less effort than returning new rows from the database to determine the maximum and minimum for each field.
This approach will give the following output
Please seriously consider this solution. If you have further questions, please just ask.

Hide a row in Excel OLAP pivot table

I have an Excel sheet which connects to a cube. The information is presented in a pivot table. The problem is that I need to hide one member of the dimension on the rows axis.
That is I have the following table.
a value1
b value2
c value3
total
I want to hide the row with value b. I cannot solve this with filters in the pivot table since the member must always be hidden and if the filter is used then a user can select it.
What I have tried so far:
Use a named set with an MDX calculation. This does not work since a named set cannot be used in filters.
Use a calculated measure IIF(currentmember = b, null, value). This does not work since the grand total still includes the value for b.
Any suggestions? I prefer not to create a scoped member in the cube specifically for this report.
In case anyone is still interested I found a solution to the problem.
Created a new measure in the cube with a null value.
Created a scope calculation for the measure in the cube, IIF(currentmember = b, null, value).
Created a new perspective in the cube list where the new measure is not visible.
Lots of work but I could not find any other options in this case.
I've searched high and low for this answer.
I had a similar issue. I was trying to calculate a measure from other 3 measures then filter and aggregate the filtered result. I came up with this:
Calculate the column in the source view table ( a - b + c = x)
Add the unfiltered calculated column (x) to the dsv
Create a named calculation in the dsv that uses a case statement to filter the original calc measure
Add the named calculation as measure
I choose to do it this way to capture the measure unfiltered first then, if another filter needs to be added or one needs to be taken off I can do so without messing with the views again. I just add the new dim to filter by to my named calculation case statement.

Resources