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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

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

 

 

amitchandak
Super User
Super User

@NickProp28 , you can use following

https://docs.microsoft.com/en-us/dax/containsstring-function-dax

https://docs.microsoft.com/en-us/dax/search-function-dax

https://docs.microsoft.com/en-us/dax/find-function-dax

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
mahoneypat
Microsoft Employee
Microsoft 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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors