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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Merleau
Helper II
Helper II

Filtering using a condition on another column in M and in DAX

 

Hello,

I need help to filter a table both in M and in DAX.

My original table looks like:

 

ID

Date

Other columns

Location

Other Columns

1

10/11/2018

 

Domestic

 

4

10/12/2019

 

International

 

2

5/13/2020

 

Domestic

 

4

1/14/2020

 

International

 

6

10/15/2018

 

Domestic

 

 

I would like to select only rows where date is before Feb 15, 2020 if the location is “Domestic” or before Dec 15, 2019 if the location is “International”.

I need the solution both in M and in DAX.

 

The final table should look like:

 

ID

Date

Other columns

Location

Other Columns

1

10/11/2018

 

Domestic

 

4

10/12/2019

 

International

 

6

10/15/2018

 

Domestic

 

 

In M, I tried the following, but the result is all wrong.

 

 

#"Filtered Rows" = Table.SelectRows(#"Source", each ( if [Location]="Domestic" then [Date] < #date(2020, 15, 2) else [Date] < #date(2019, 15, 12) ) ),

 

I have no idea how to go about it in DAX.

Can somebody pls help?

Thank you

1 ACCEPTED SOLUTION
Jimmy801
Community Champion
Community Champion

Hello @Merleau 

 

this is the solution for Power query

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI00Dc01DcyMLQEclzyc1OLSzKTlWJ1opVMoLJGMFnPvJLUorzEksz8vMQcsBIjoKipvqExUIWRAVb9+oYmMElM7WZQG0xBNlig6I8FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Date = _t, Location = _t]),
    Trans = Table.TransformColumns(Source,{"Date",each Date.From(_, "en-US" )}),
    SelRows = Table.SelectRows(Trans, each (_[Location]="Domestic" and _[Date] < #date(2020, 2, 15)) or (_[Location]="International" and _[Date] < #date(2019,12,15)))
in
    SelRows

 

in DAX you can add a new column like this and filter in the visuals

FilterColumn = if ( and([Location]="Domestic", [Date]<date(2020,2,15)),TRUE(), if (and([Location]="International", [Date]<date(2019,12,15)),true,false))

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

View solution in original post

2 REPLIES 2
Jimmy801
Community Champion
Community Champion

Hello @Merleau 

 

this is the solution for Power query

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI00Dc01DcyMLQEclzyc1OLSzKTlWJ1opVMoLJGMFnPvJLUorzEksz8vMQcsBIjoKipvqExUIWRAVb9+oYmMElM7WZQG0xBNlig6I8FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Date = _t, Location = _t]),
    Trans = Table.TransformColumns(Source,{"Date",each Date.From(_, "en-US" )}),
    SelRows = Table.SelectRows(Trans, each (_[Location]="Domestic" and _[Date] < #date(2020, 2, 15)) or (_[Location]="International" and _[Date] < #date(2019,12,15)))
in
    SelRows

 

in DAX you can add a new column like this and filter in the visuals

FilterColumn = if ( and([Location]="Domestic", [Date]<date(2020,2,15)),TRUE(), if (and([Location]="International", [Date]<date(2019,12,15)),true,false))

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

This is perfect @Jimmy801 

Thank you.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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