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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

How to remove/exclude data from query

Hi there, 

 

I am getting data from folder. In there are multiple excel files. However in each excel I only need a certain date range example for October's excel file, I only need 1-31 October data. The rest can be ignored or removed. There is a date column in the excel and all the excel are formatted the same way. Appreciate any help. Thanks.

2 ACCEPTED SOLUTIONS

@Anonymous ,

Hi,

1 Go to Add Column in top menu.

2 Click on Custom Column

 

Dinesh_Suranga_0-1665717716316.png

3 Add following code.
Please change [source.name] and [DateColumn] as your table.

if [source.name] = "Excel 1 - All" and Date.MonthName( [DateColumn]) = "May" then "True" else

if [source.name] = "Excel 2 - All" and Date.MonthName( [DateColumn]) = "June" then "True" else

if [source.name] = "Excel 3 - All" and Date.MonthName( [DateColumn]) = "July" then "True" else

if [source.name] = "Excel 4 - All" and Date.MonthName( [DateColumn]) = "August" then "True" else "False"

Thank you.

View solution in original post

Anonymous
Not applicable

Hi @Anonymous ,

No, you can update the formula as below:

1. If the year of the data column is equal to 2021

if [source.name] = "Excel 1 - All.xls"

   and Date.Year([DateColumn]) = 2021

   and Date.MonthName([DateColumn]) = "May"

then "True"
else "False"

yingyinr_0-1666228640918.png

 

2. If the year of the data column is equal to the year of current date

if [source.name] = "Excel 1 - All.xls"

   and Date.Year([DateColumn]) = Date.Year(DateTime.LocalNow())

   and Date.MonthName([DateColumn]) = "May"

then "True"
else "False"

yingyinr_1-1666228743511.png

Best Regards

View solution in original post

12 REPLIES 12
Dinesh_Suranga
Continued Contributor
Continued Contributor

@Anonymous 

Hi,

Your Date column data type should be Date before do this.

1 Select the date column.

2 Click drop down icon in right side ( highlighted in red)
3 Click on Date Filters
4 Click on Between.

5 Select date range you want.

Dinesh_Suranga_0-1665711787360.png

Thank you.

Anonymous
Not applicable

However, multiple excels are already combined in the query. So I can see the excels under source.name. So I am trying to clean this up.

Excel 1 - All the days in May, remove all the other dates before and after May.
Excel 2 - All the days in June, remove all the other dates before and after June.
Excel 3 - All the days in July, remove all the other dates before and after July.
Excel 4 - All the days in August, remove all the other dates before and after August.

Should I then import one by one and treat it as different query?

@Anonymous 

Hi,

You can add a new column with two conditions.

If source.name = "Excel 1" - All & Date.MonthName = May then "True"  else "False"
Like this. Then you can filter True cells from that column. 

Switch case will be easy than If funtion.

If you want help to create formula please let me know.

Thank you.

Anonymous
Not applicable

Sorry how do u do with switch case? 

For if function can provide step by step? 

Thanks.

@Anonymous ,

Hi,

1 Go to Add Column in top menu.

2 Click on Custom Column

 

Dinesh_Suranga_0-1665717716316.png

3 Add following code.
Please change [source.name] and [DateColumn] as your table.

if [source.name] = "Excel 1 - All" and Date.MonthName( [DateColumn]) = "May" then "True" else

if [source.name] = "Excel 2 - All" and Date.MonthName( [DateColumn]) = "June" then "True" else

if [source.name] = "Excel 3 - All" and Date.MonthName( [DateColumn]) = "July" then "True" else

if [source.name] = "Excel 4 - All" and Date.MonthName( [DateColumn]) = "August" then "True" else "False"

Thank you.

Anonymous
Not applicable

Hi Dinesh, 

IT worked! If I only want to see data for the month and year(May,2022), What should i change to the code? Because in the data there are other years too (2019, 2020, 2021). Currently it is giving me all the May dates in different years. Thanks again.

Cheers

Darren

@Anonymous 

Do you have separate calendar table?

 

Anonymous
Not applicable

No, I don't. Only the date columns with all the dates. 

Anyway we could edit the script to read the dates mm/yyyy (05/2022)? Maybe it might work? Thanks.

Anonymous
Not applicable

Hi @Anonymous ,

You can make a little change on the formula which provided by @Dinesh_Suranga  as below(just for example to get the data from 05/2022):

if [source.name] = "Excel 1 - All"

   and Date.Year([DateColumn]) = Date.Year(DateTime.LocalNow()) --You can put 2022 here

   and Date.MonthName([DateColumn]) = "May"

then "True"
else "False"

Best Regards

Anonymous
Not applicable

Do i put the 2021 in the bracket below or outside? Thanks. Tried it but got errors.

 

if [source.name] = "Excel 1 - All.xls"

   and Date.Year([DateColumn]) = Date.Year(DateTime.LocalNow(2021))

   and Date.MonthName([DateColumn]) = "May"

then "True"
else "False"

Anonymous
Not applicable

Hi @Anonymous ,

No, you can update the formula as below:

1. If the year of the data column is equal to 2021

if [source.name] = "Excel 1 - All.xls"

   and Date.Year([DateColumn]) = 2021

   and Date.MonthName([DateColumn]) = "May"

then "True"
else "False"

yingyinr_0-1666228640918.png

 

2. If the year of the data column is equal to the year of current date

if [source.name] = "Excel 1 - All.xls"

   and Date.Year([DateColumn]) = Date.Year(DateTime.LocalNow())

   and Date.MonthName([DateColumn]) = "May"

then "True"
else "False"

yingyinr_1-1666228743511.png

Best Regards

Anonymous
Not applicable

thank you @Anonymous and @Dinesh_Suranga. Both lifesavers! have a good one. take care

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.