Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data Studio Case Function Metric/Dimension Error

I have made use of the Case function in Data Studio to ascertain whether a value is over or under £6,000 and present one of two figures dependent on output. These two figures are calculated fields.

First Case statement :

(Over or Under) -

CASE WHEN Cost <= 6000 
THEN 1 
ELSE 0 
END

Second Case statement -

(Total Cost) -

CASE WHEN Over or Under 6,000= 0 
THEN Cost if over 6,000
ELSE Cost if under 6,000
END

Cost if over 6,000 is calculated in the following way -

Cost + (Cost * .1)

and Cost if under 6,000 is calculated -

Cost + 600

This is working perfectly on one report, but when I replicate it in another report with identical data I get the following error message -

An expression can have either metrics, or dimensions, but not both

All calculated fields are defined as numbers so why am I getting this error message? And why would it work in one report and not another?

like image 618
Hazel Popham Avatar asked Jul 31 '18 14:07

Hazel Popham


1 Answers

I find Data Studio a bit funny with combining multiple calculated fields. I'd try combining the total into a single calculation.

Cost 
*
CASE WHEN Cost > 6000 THEN 1.1 ELSE 1 END
+
CASE WHEN Cost <= 6000 THEN 600 ELSE 0 END

Sample Report: https://datastudio.google.com/open/1wWrNOgwUG9NGhrjCIof19Hv4Yq9TwBoX

Sample Data: https://docs.google.com/spreadsheets/d/1C_3ZMdQeHnKRkCYfVrlAB_QkI8qKcPfMhLT3QTFS0n4/edit?usp=sharing

Field settings: Data source field settings

like image 111
Taavi Randmaa Avatar answered Sep 30 '22 16:09

Taavi Randmaa