• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Filter based on multiple conditions

Vatti5

New Member
Hello,

I have a set of data that has multiple customers, as well as origin and destination countries. The Power BI file is connected directly to a data warehouse and I am not able to add columns to it. The attached file is an example of some of the columns I am working with, however there is no currency column (I put that in just to show the intended output). If the Customer is "ABC Plastics" or "DEF Machinery" AND the origin and destination countries are both "MX", it should have the currency as "MXN," otherwise show "USD." I've had no luck creating measures that will work. Appreciate any help/advice!

Thanks
 

Attachments

AlanSidman

Well-Known Member
I believe that you can run Mcode in PBI, here is the full Mcode when I use your file in PQ

Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Customr Name", type text}, {"Cost", Int64.Type}, {"Origin Country", type text}, {"Destination Country", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Currency", each if Text.Contains([Customr Name],"ABC") or Text.Contains([Customr Name],"DEF") and [Origin Country]= "MX" and [Destination Country] = "MX" then "MX" else "US")
in
    #"Added Custom"
The line of code you need is on the #'Added Custom" line
 
Top