Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
NickProp28
Post Partisan
Post Partisan

Need help on Like statement DAX

Dear experts,

 

NickProp28_0-1593082099920.png

Based on the table, 
I have two condition need to calculate which is
i.)Only want get the data (Profit) which Origin/Dest is under MYKUL,MYPEN,CNSHA,SGSIN. Other from this, data(Profit) will ignore.
ii.)If Origin=Dest. Data will be ignore too (Example like CNSHA=CNSHA).
With the help, i able get DAX.
=Calculate(sum(table[profit]), filter(Table, table[origin]<>table[destination] && table[origin] in {"MYKUL","MYPEN","CNSHA","SGSIN"}.
But if I want to use LIKE (IN SQL) statement, for example calculate origin column which the start with "MY.." , "CN..".
How the DAX function will be like. 

Hope you will have a great day!
Best thanks.

 

2 ACCEPTED SOLUTIONS
harshnathani
Community Champion
Community Champion

Hi @NickProp28 ,

 

 

I Tried  replicating this with some dummy data. Work well for me.

 

1.jpg

 

 

 

Count =
CALCULATE (
    SUM ( Financial[Job Profit] ),
    FILTER (
        Financial,
        Financial[Origin] <> Financial[Dest]
            && LEFT (
                Financial[Origin],
                2
            )
                IN {
                "SG",
                "MY"
            }
            && LEFT (
                Financial[Dest],
                2
            )
                IN {
                "SG",
                "MY"
            }
    )
)

 

 

 

Just to troubleshoot ,try to Trim your Origin and Destination Columns in Power Query to removing leading spaces if any.

 

Regards,

Harsh Nathani

 

 

View solution in original post

5 REPLIES 5
NickProp28
Post Partisan
Post Partisan

Hi all,

@amitchandak @mahoneypat  @harshnathani ,

 

I try it and come out with this DAX.

But the calculation is wrong. Can you guys take a look on my DAX.

Count = CALCULATE(SUM(Financial[Job Profit]),FILTER(Financial,Financial[Origin]<>Financial[Dest] && LEFT(Financial[Origin],2) IN {"SG","MY"} && LEFT(Financial[Dest],2) IN {"SG","MY"}))

 

This is from https://www.sqlbi.com/articles/from-sql-to-dax-string-comparison/
Hope you guys have a great day.

Best thanks.

 

 

Hi @NickProp28 ,

 

 

I Tried  replicating this with some dummy data. Work well for me.

 

1.jpg

 

 

 

Count =
CALCULATE (
    SUM ( Financial[Job Profit] ),
    FILTER (
        Financial,
        Financial[Origin] <> Financial[Dest]
            && LEFT (
                Financial[Origin],
                2
            )
                IN {
                "SG",
                "MY"
            }
            && LEFT (
                Financial[Dest],
                2
            )
                IN {
                "SG",
                "MY"
            }
    )
)

 

 

 

Just to troubleshoot ,try to Trim your Origin and Destination Columns in Power Query to removing leading spaces if any.

 

Regards,

Harsh Nathani

 

 

mahoneypat
Employee
Employee

One simple way to do this would be to add a column in query or DAX that shows the first two letters in that column.  Then you can use your same approach/measure with that new column "... in {"MY", "CN"} ..."

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


harshnathani
Community Champion
Community Champion

HI @NickProp28 ,

 

 

You can have a look at this

 

https://www.sqlbi.com/articles/from-sql-to-dax-string-comparison/

 

Regards,

Harsh Nathani

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.