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
sovereignauto
Helper III
Helper III

Conditional Filter Power Query - Same Column

Afternoon,

Im looking to filter a column [updated_date] (date/time) for the last 2 months or the last 6 months if [type]="ABC"

 

So all records for the last 6 months where type = "ABC" 

and every other record for the last 2 months 

thank you! 

1 ACCEPTED SOLUTION
v-robertq-msft
Community Support
Community Support

Hi, @sovereignauto 

According to your description, I can clearly understand your requirement, you can try my steps in the Power query:

This is the test data I created:

v-robertq-msft_0-1621246139974.png

 

  1. Create a custom column and enter it like this:

v-robertq-msft_1-1621246139979.png

if Date.IsInPreviousNMonths([Date],2) or  Date.IsInCurrentMonth([Date])

then

1

else

if Date.IsInPreviousNMonths([Date],6) and [Type]="ABC"

then 1 else 0
  1. Filter the table like this:

v-robertq-msft_2-1621246139985.png

 

  1. Remove the custom column:

v-robertq-msft_3-1621246139986.png

 

  1. Then click on the “Close and apply” to import the filtered table into the Power BI

v-robertq-msft_4-1621246139987.png

 

And you can get what you want.

You can download my test pbix file below

 

If this result is not what you want, you can post some sample data(without sensitive data) and your expected result.

How to Get Your Question Answered Quickly 

Thank you very much!

 

Best Regards,

Community Support Team _Robert Qin

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
mah_priya94
Helper I
Helper I

Hi, If your Source is SQL then You can use "Query Folding" in order to achieve this.
Create a parameter (Parameter_Name) and in the where clause set the condition as follows:
Select * from table_name where the Field_name = Parameter_name

v-robertq-msft
Community Support
Community Support

Hi, @sovereignauto 

According to your description, I can clearly understand your requirement, you can try my steps in the Power query:

This is the test data I created:

v-robertq-msft_0-1621246139974.png

 

  1. Create a custom column and enter it like this:

v-robertq-msft_1-1621246139979.png

if Date.IsInPreviousNMonths([Date],2) or  Date.IsInCurrentMonth([Date])

then

1

else

if Date.IsInPreviousNMonths([Date],6) and [Type]="ABC"

then 1 else 0
  1. Filter the table like this:

v-robertq-msft_2-1621246139985.png

 

  1. Remove the custom column:

v-robertq-msft_3-1621246139986.png

 

  1. Then click on the “Close and apply” to import the filtered table into the Power BI

v-robertq-msft_4-1621246139987.png

 

And you can get what you want.

You can download my test pbix file below

 

If this result is not what you want, you can post some sample data(without sensitive data) and your expected result.

How to Get Your Question Answered Quickly 

Thank you very much!

 

Best Regards,

Community Support Team _Robert Qin

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

So i added the Column as you and @amitchandak  suggested. 

i Guess my issue is that it still syncs over 10m records so guess i need to filter before load into powerbi is that right? 

amitchandak
Super User
Super User

@sovereignauto , Try a new column like and then you can filter 

 

if Date.IsInPreviousNMonths([Date]) && [type]="ABC" then 1 else 0

 

if need use Date.IsInCurrentMonth

 

if (Date.IsInPreviousNMonths([Date]) ||   Date.IsInCurrentMonth([Date]) ) && [type]="ABC" then 1 else 0

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.