I have the a dataset that is a mix of various text and numbers, and want to identify specific ones as code. Here are some scenarios I have encountered -
Column A
Column B
10.01.01
Code
40.001
Code
3000
Code
2000.0001 - ABC
Code
500.ABC
Not Code
ABC DEF
Not Code
01_ABC
Not Code
Would appreciate any assistance here.
Thanks!
Here's the expression you are looking for:
Column C =
IF (
AND (
FIND ( "ABC", 'Cost Code'[Column A], 1, 0 ) > 0,
FIND ( "-", 'Cost Code'[Column A], 1, 1 ) = 1
),
"Not Code",
"Code"
)
Related
I'm having a problem with what should be a very simple solution.
https://i.stack.imgur.com/QFTbm.jpg
How can i get the latest value xyz and abc in the field C .
Very new to quicksight.
There might be a simple solution that
I might not know about.
If you want to have a new calculated field which has the latest value of C for each column (A, B etc..), then you could add these as follows:
latest A
maxOver(
ifelse(
{Date} = maxOver({Date}, [A], PRE_FILTER), C,
null
),
[]
PRE_FILTER
)
latest B
maxOver(
ifelse(
{Date} = maxOver({Date}, [B], PRE_FILTER), C,
null
),
[]
PRE_FILTER
)
and so on
lets say i have a column with many lines but only two values, A and B:
i am trying unsuccessfully to count only lines with A - in a summary calculation for a dashboard (without making a new column for this specific calculation)
the expression which gives me syntax error is this:
count([column] = 'A')
any suggestion?
You'll need to use an if then else construct:
count( if([Column]='A') then ([Column]) else (Null))
You can use IF-THEN-ELSE or CASE-WHEN-THEN-ELSE to create your own count:
sum(
if ([Query Item] = 'A')
then (1)
else (0)
)
or
sum(
case
when [Query Item] = 'A'
then 1
else 0
end
)
I've got about 20 different metrics across 10 locations and want to make a matrix with metrics as rows and the locations as the different columns. The issue I'm running into is that the metrics are different data types, some are whole numbers, some are %s and some are $s.
Is there any way to custom format each row as a different data type like there is in excel?
Edit: Sorry I wasn't clear. I don't want the same value showing up multiple times.
See below screenshots.
Test Data Screenshot:
What I want, but I want it in Power BI, not Excel:
What I don't want when I use measures that are formatted as different data types:
The formatting is not controlled by the rows or columns but rather each measure can be assigned its own data type using the Modeling tab.
Edit: I see a few options here.
Option 1: Write a text measure that switches formats like this:
FormatMetric =
VAR Val = SUM ( TestData[Value] )
RETURN
SWITCH (
SELECTEDVALUE ( TestData[Metric] ),
"# quantity", FORMAT ( Val, "0" ),
"$ Sales", FORMAT ( Val, "$0.00" ),
"% to plan", FORMAT ( Val, "0%" )
)
You'll get a table that looks like this:
Be aware that this measure returns text values and won't work in a chart.
Option 2: Create three separate measures and format each separately:
# quantity = CALCULATE ( SUM ( TestData[Value] ), TestData[Metric] = "# quantity" )
$ Sales = CALCULATE ( SUM ( TestData[Value] ), TestData[Metric] = "$ Sales" )
% to plan = CALCULATE ( SUM ( TestData[Value] ), TestData[Metric] = "% to plan" )
If you make sure you have Format > Values > Show on rows turned on and put these three measures in the Values box:
These measures can be used in charts.
Option 3: Pivot your data table on the Metric column in the query editor so you don't have mixed data types in a single column. Your data table should look like this now:
From here, you can write three simple measures format as in the previous option:
# quantity = SUM ( Pivot[# quantity] )
$ Sales = SUM ( Pivot[$ Sales] )
% to plan = SUM ( Pivot[% to plan] )
I have this expression
vOther_OS =
CALCULATE (
SUM ( OS_excel[OS_AMOUNT] ),
Claims_excel[COVER_NAME]={"abc", "def"},Premium_Excel[LOB]="Caar"
)
when i try above expression this shows an error
"A table of multiple values was supplied where a single value was expected"
so this message clearly shows there should 1 value in bracket where i want more than 1 value
as i do this in qliksense expression
sum({<COVER_NAME -= {"abc", "def"},LOB = {'Caar'}>}OS_AMOUNT)
Change your formula to:
vOther_OS =
CALCULATE (
SUM ( OS_excel[OS_AMOUNT] ),
Claims_excel[COVER_NAME] IN { "abc", "def" },
Premium_Excel[LOB] = "Caar"
)
My dataset looks like the following:
( A, (1,2) )
( B, (2,9) )
I would like to "flatten" the tuples in Pig, basically repeating each record for each value found in the inner-tuple, such that the expected output is:
( A, 1 )
( A, 2 )
( B, 2 )
( B, 9 )
I know this is possible when the tuples (1,2) and (2,9) are bags instead.
Your insight is good; it's possible by transforming the tuple in a bag. The schema we want to aim for is: {a: chararray,{(chararray)}} for example: (A,{(1),(2)})
Here is the solution to your problem:
A = LOAD 'data.txt' AS (a:chararray,b:(b1:chararray,b2:chararray));
B = FOREACH A GENERATE a, TOBAG(b.b1,b.b2);
C = FOREACH B GENERATE a, FLATTEN($1);
The magic part is the TOBAG operator.
You can use DataFu's UDF TransposeTupleToBag (http://datafu.incubator.apache.org/docs/datafu/1.1.0/datafu/pig/util/TransposeTupleToBag.html) and then flatten the bag to get a row per item in the bag.
I know this is an old thread but I could not get the above method to work. Thought I will share my findings.
input: (1-2-3, abc)
(4-5-6, xyz)
desired output:
(1, abc)
(2, abc)
(3, abc)
(4, xyz)
(5, xyz)
(6, xyz)
Initially, I used STRSPLIT that generates a tuple resulting in the similar input as above but was unsuccessful.
output = FOREACH input GENERATE FLATTEN(TOBAG(STRSPLIT($0, '-'))), $1
This resulted in the output as:
(1,2,3,abc)
(4,5,6,xyz)
However, when I used tokenize and replace functions I got the desired output.
output = FOREACH input GENERATE FLATTEN(TOKENIZE(REPLACE($0,'-', ' '))), $1;