Index
Is MTO
ShouldBeMTO
1
TRUE
null
2
TRUE
null
3
TRUE
null
4
TRUE
null
5
FALSE
null
6
TRUE
TRUE
7
FALSE
TRUE
8
etc.
...
I have data like that; I want to overwrite Is MTO with values from ShouldBeMTO except when null. - e.g. lines 1 to 5 stay the same, line 7 goes from False to True
The Merge columns option concatenates columns with a delimiter. I was thinking of trying to replace null with something then XOR the columns but that's not quite what I want.
Any hints?
Oh it's super simple:
Add Column->Add Custom Column then
= if [ShouldBeMTO] = null then [Is MTO] else [ShouldBeMTO]
I was worried the syntax would look at entire columns of data but this is row-by row
Related
I have this type of table in Power BI:
id
isPromoter
path
aaa-111-000
false
sqe-432-w14/2aq-4ec-t66/aaa-111-000/
sss-342-r34
true
a3e-543-1sd/34d-245-svt/s3a-bnj-klo/sss-342-r34/
hhy-e90-y7u
false
a3e-543-1sd/34d-245-svt/s3a-bnj-klo/sss-342-r34/hhy-e90-y7u/
...
...
...
So, as you can see, the second id is contained in both in the second and in the third path; this only can happen if the user is a Promoter.
I would like another field which counts how many times each id is contained in all paths (beside itself); so it should be 0 if the user is not a promoter and >0 if it is.
id
isPromoter
path
children
aaa-111-000
false
sqe-432-w14/2aq-4ec-t66/aaa-111-000/
0
sss-342-r34
true
a3e-543-1sd/34d-245-svt/s3a-bnj-klo/sss-342-r34/
3
hhy-e90-y7u
false
a3e-543-1sd/34d-245-svt/s3a-bnj-klo/sss-342-r34/hhy-e90-y7u/
0
...
...
...
...
I know that there is the function Text.Contains([path],[id]) but it is only true for the current row. I don't know how to do the count for all rows
Add column ... custom column ... name it children, use formula
= List.Count(List.FindText(#"PriorStepNameHere"[path],[id]))-1
Can't find the error in formula - the value is calculated throughout the column (when keeping errors - no rows shown), but I can't apply the changes though.((
if [Index] > 0 then
if articles_pivot{[Index]-1}[IN] <> null (when omitted the error remains) and [IN]=null then
articles_pivot{[Index]-1}[IN]
else null
else null
Thank you for advice!
If I an reading it right, all you really need to do is right click IN column and do fill ... down...
Otherwise, see if this works
= try if articles_pivot{[Index]-1}[IN] <> null and articles_pivot{[Index]}[IN] = null then articles_pivot{[Index]-1}[IN] else null otherwise null
decided to make it another way - in the origin table I've added Index column starting 0 and in the pivot table (made by pivoting the origin one) I've added index column starting 1, then merged them..)
I'm used to writing in JavaScript so I am approaching this thinking about SWITCH statements and of course the classic if else...
I just want to check if the data in a row is TRUE, and if it is count it. If the value is not true, don't add it to the count.
I'm thinking something like this would work:
CASE
WHEN is_it_true_or_false = false
THEN COUNT_DISTINCT ( id ) //using id to address that specific row and add it to the count
END
It can be achieved by using either of the following CASE statements and aggregating the Calculated Field as required - COUNT_DISTINCT (Unique IDs of TRUE values) or COUNT (All TRUE values):
1) Where is_it_true_or_false is a Boolean OR String Field:
CASE
WHEN REGEXP_MATCH(is_it_true_or_false, "((?i)TRUE)") THEN id
ELSE NULL
END
2) Where is_it_true_or_false is a Boolean Field:
CASE
WHEN is_it_true_or_false = TRUE THEN id
ELSE NULL
END
Google Data Studio Report and GIF to elaborate:
I want to create a calculated column that increments by 1 every time it meets a true in bool column. any ideas ?
in the image at left is the data table and at right the desired result
Something like the formula below should work
case when [bool]=True then sum(If([bool]=True,1,0)) over (AllPrevious([id])) else 0 end
I have a query below from source this is how Active flag for target is derived
select case when active_end_date is null then 'Y' else 'N' end
from csi_item_instances cii
where instance_id = <<INSTALL BASE ID>> --- (MP.INSTALL_BASE_ID)
I am comparing the active field value using the SQL below, is there better way to do this?
select * from stgdba.Stg_s_csi_item_instances cii, MDHDBA.M_CUSTOMER_PRODUCT mp
where cii.instance_id= MP.INSTALL_BASE_ID
and cii.active_end_date is null
and MP.ACTIVE_FLAG = 'N'
If that value is to be permanently calculated like that, you could do that in a view / computed column, which would make the logic a bit more permanent and not repeated all over the place.
(Stylistically, I would also try using ANSI joins a bit more.)