If column A contain "TP" then "Yes".
If column A contain "TP-" then "Yes".
If column A contain "-A" then "Yes".
If column A does not contain "TP","TP-","-A" then desired result is "No".
In Excel I am applying the following formula in order to get the my final result.
=IF(SUM(COUNTIF(A2,{"*TP","*TP-*","*-A*"})),"YES","NO")
Note:
Column A contain text and numbers and Prefix and suffix or prefix with suffix as well.
DATA and DESIRED RESULT;
ITEM DESIRED RESULT
1234567TP YES
1234567TP-0001 YES
1234567TP-0001DR YES
1234567TP-DR0001DR YES
1234567TP-A0006DR YES
1234567TP-A90001DR YES
1234567TP-A0001DR YES
7674859YO-A891 YES
456YO-A12 YES
87654HI-A0000098 YES
1234678VU NO
1234678VU-P00094 NO
1234678VU-P00089 NO
1234678VU-P00567 NO
You can use this DAX formula to obtain the expected result:
Desired Column =
IF(
CONTAINSSTRING( 'Table'[ITEM], "TP" ), "YES",
IF(
CONTAINSSTRING( 'Table'[ITEM], "TP-" ), "YES",
IF(
CONTAINSSTRING( 'Table'[ITEM], "-A" ), "YES", "NO"
)
)
)
Just to mention, the "TP-" condition is not needed because you have the "TP" condition. I just added to keep your logic.
Either use IF with the OR operator ||
NewColumn2 =
IF(
CONTAINSSTRING( 'Table'[Item],"tp") || CONTAINSSTRING( 'Table'[Item],"-a"), "Yes",
"No"
)
or if you have many possible outcomes, switch can be cleaner
NewColumn =
SWITCH(
TRUE(),
CONTAINSSTRING( 'Table'[Item],"tp"), "Yes",
CONTAINSSTRING( 'Table'[Item],"-a"), "Yes",
"No"
)
Related
I've got the below as a transformation step against a table, but it isn't working. I think it's due to the fact that it's not a text field, but a number field.
= Table.ReplaceValue(
#"Custom1",
each [Sign],
each if Text.StartsWith([Account No], "4") then -1 else [Sign] ,
Replacer.ReplaceText,{"Sign"}
)
If I create a Step with the following, I get correct results for those [Account No] valuese that start with a 4.
= Table.AddColumn(#"Replaced Value2", "AccountNoStartsWithFour", each Text.StartsWith([Account No], "4"))
Does anyone know what I need to do to get this working?
There are values such as:
4001
4201
1240
3556
I have a sample file here: https://easyupload.io/7v68iw
Is this what you require?
= Table.ReplaceValue(AccountNoStartsWithFour, each [Sign] ,each if Text.StartsWith([Account No], "4") then -1 else [Sign],Replacer.ReplaceValue,{"Sign"})
New to DAX and PowerBI and am trying to solve a particular problem.
I have a dataset that is approximated by the following (with column names Customer, Department, Merchant, and Product, respectively):
Super Mario World = {
("Yoshi's Island", "Performance Enhancers", "Toad", "Mushroom"),
("Yoshi's Island", "Performance Enhancers", "Toad", "Fire Flower"),
("Vanilla Dome", "Performance Enhancers", "Toad", "Fire Flower"),
("Vanilla Dome", "Performance Enhancers", "Toad", "Star"),
("Chocolate Island", "Performance Enhancers", "Wendy O. Koopa", "Dino Torch"),
("Chocolate Island", "Performance Enhancers", "Dino Rhino", "Dino Torch"),
("Chocolate Island", "Obstacle", "Dino Rhino", "Hot Mud"),
("Valley of Bowser", "Obstacle", "Toad", "Koopa Shell"),
("Valley of Bowser", "Obstacle", "Koopa Troopa", "Koopa Shell"),
("Valley of Bowser", "Performance Enhancers", "Toad", "Mushroom"),
("Donut Plains", "Obstacle", "Koopa Troopa", "Hammers"),
("Donut Plains", "Obstacle", "Koopa Troopa", "Bullet Bill"),
("Donut Plains", "Performance Enhancers", "Toad", "Cape Feather"),
("Donut Plains", "Performance Enhancers", "Toad", "Fire Flower")
}
The major difference between the above table and my actual data is that Customer, Department, Merchant, and Product are all in individual tables that have relationships to a central fact table. I couldn't figure out how to make that clear in this post other than to state it, so apologies.
I would like to return all customers that meet the selection for department and merchant but do NOT meet the selection for product. So, if I select Performance Enhancers, Toad, and Mushroom, I want to return Vanilla Dome and Donut Plains. I do not want to return Valley of Bowser or Yoshi's Island because Mushroom is a product associated with those customers. Similarly, if I selected Obstacle, Koopa Troopa, and Koopa Shell, I'd want to return Donut Plains only.
I've tried a ton of iterations of this, most prominently something like this https://community.powerbi.com/t5/Desktop/Tricky-Slicer-Options/m-p/573381#M270846. The goal in that example is to create a disconnected table and use that disconnected table as a slicer in conjunction with that calculation. But I haven't been successful at making it work.
I also made a couple of efforts at writing a measure that defined different variables for each of the the three conditions and then a simple if statement. Something like this:
Customer Filter =
VAR a = (
SuperMarioWorld[Department]
)
VAR b = (
SuperMarioWorld[Merchant]
)
VAR c = (
SuperMarioWorld[Product]
)
RETURN
IF (
SELECTEDVALUE(SuperMarioWorld[Department]) = a &&
SELECTEDVALUE(SuperMarioWorld[Merchant]) = b &&
NOT SELECTEDVALUE(SuperMarioWorld[Department]) = c,
TRUE,
FALSE
)
This hasn't worked for me (and doesn't even register as valid for a number of reasons I can't totally decipher).
Any help would be greatly appreciated!
It simplifies things that, from your description, it's clear that you will be disallowing multiple selections per slicer.
Define a measure:
MyFilter :=
VAR SelectedProduct =
MIN( Products[Product] )
VAR SelectedMerchant =
MIN( Merchants[Merchant] )
VAR SelectedDepartment =
MIN( Departments[Department] )
VAR MyFilter1 =
CALCULATE(
COUNTROWS(
FILTER(
Data,
Data[Department] = SelectedDepartment
&& Data[Merchant] = SelectedMerchant
)
),
ALL( Products[Product] )
) > 0
VAR MyFilter2 =
COUNTROWS(
FILTER(
Data,
Data[Product] = SelectedProduct
)
) = 0
RETURN
MyFilter1 * MyFilter2
You can then drag this measure into the filters area for the visual and set it equal to 1.
I am new to Power BI just started my IT career. how do I solve this problem, its not a duplicate question.
Note: I have already got the required output using conditional formatting, but I have been asked to do the same by creating DAX measure for the report to the change the background color
This is my input data:
Here are the predefined conditions I need in my DAX query.
If Type1 >=0, <=2 and then Yellow
If Type1 >=3, <=5 and then Blue
If Type1 >=5, <=20 and then Orange
Lookup column is "Column 2"
This is the expected output:
This is what I have tried:
Measure 2 =
VAR q =
SELECTEDVALUE('Table 1'[1/1/2021])
Return
SWITCH(
True(),
q<=2 "Yellow",
q>=3,q<=4 "Blue"
q>=5,Q<=20 "Orange"
)
But its not working and I have also tried the same above logic using IF statement that did not work either.
Try changing your SWITCH statement to this:
SWITCH(
TRUE(),
q<=2, "Yellow",
q>=3 && q<=4, "Blue",
q>=5 && q<=20, "Orange"
)
It worked for me.
I am trying to add conditional formatting into my table and although it works for some of the data, about half of it is not returning any value for the condition.
Condition = MAXX('2020 PNRs',
IF('2020 PNRs'[2020-2021] <=1, 1,
IF('2020 PNRs'[2020-2021] <=10000 , 2,
IF('2020 PNRs'[2020-2021] >10000 , 3))))
2020-2021 is a calculated measure
2020-2021 =
SUM('TTV'[2020TTV]) + SUM('TTV'[2021TTV])
but it is quite simple so I am not sure if that has anything to do with why it's not working?
Your Condition formula filters '2020 PNRs' table. It might be that the top part of your screenshot presents results that are not available on '2020 PNRs', but are rather sourced from some other table (e.g. '2021 PNRs'?). It would be good for us to understand the source of your table and your data model.
In the meantime, I suggest testing the following measure:
Condition =
SWITCH(
TRUE(),
[2020-2021], 1,
[2020-2021] <=10000, 2,
[2020-2021] >10000, 3
)
If this still doesn't work, then return the value of [2020-2021] measure as the last argument to understand the issue:
Condition =
SWITCH(
TRUE(),
[2020-2021], 1,
[2020-2021] <=10000, 2,
[2020-2021] >10000, 3,
[2020-2021]
)
quick question:
I have a total amount that is divided into several classifications, like so:
Total: 7bn
Classification 1: 3bn,
Classification 2: 1bn,
... ,
Classification N: 0,3M
N is such a big number that when I put in a graph, most of the classifications don't even show up in there, so my manager suggested that I took anything that represents less than 5% of the total 7bn and classified them as "Others" to put it all together in the visual.
Then I made a measure "% of total" like:
% of total =
divide(
sum(values),
sumx(
allselected(table),
values
)
)
And this actually works perfect, except...
I wanna make a measure (or calculated column) that returns something like:
new classification =
if(
[% of total] > 0.05,
"Others",
[classification]
)
just to classify for me in the graph
but then only one of the new classifications returns as the old one, the rest returns "Others", but I know there's more than one, according to [% of total].
Can you think of another way to make this work? Is this a dumb question?
Thanks in advance
Create 2 separate measure for [others] & [classification] and create your final measure as below-
new classification =
var is_greater = IF([% of total] > 0.05, 1, 0)
RETURN
SWITCH(
is_greater ,
1,[Others]",
[classification]
)