Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin 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.
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
Solved! Go to Solution.
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
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 your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
15 | |
12 | |
8 | |
8 | |
7 |
User | Count |
---|---|
15 | |
13 | |
9 | |
7 | |
6 |