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
miltenburger
Helper V
Helper V

Automatically delete data from import

Hi all,

 

Currently i'm finishing my intership assignment. But i face 1 issue during refreshing my data.

Currently I import all my data into Power Bi (I also tried DirectQuery but it is way to slow).

I import all my data from a SQL Database, where I have a query which says: take all the data from now till 12 months ago. Works perfect.

 

But when I refresh my data next week, the SQL statement still works fine, but the data from 12 months ago + 1 week is still in my imported data list. Is there a way to automatically delete the data from 12 months / + 1 week (So for instance the data from 30-10-2016 till 5-11-2016)

 

Kind regards

1 ACCEPTED SOLUTION

Hi @Abduvali,

 

Instead of using SQL statement, you should also be able to simply use Date.IsInPreviousMonth function(M) in Advanced Editor to import data from now till 12 months ago. Smiley Happy

    #"Filtered Rows" = Table.SelectRows(dbo_DimDate, each Date.IsInPreviousNMonths([FullDateAlternateKey], 12))
in
    #"Filtered Rows"

filter.PNG

 

Regards

View solution in original post

10 REPLIES 10
jthomson
Solution Sage
Solution Sage

Should be possible in Power Query to run Date.IsInPreviousYear on your date field and filter out those that aren't

Abduvali
Skilled Sharer
Skilled Sharer

Hi @miltenburger,

 

Are you trying to display information between these days only exp:  30-10-2016 till 5-11-2016???

 

 

Regards

Abduvali

Hi @Abduvali,

 

Thanks for fast reply.

No I am displaying all the data from last 12 months. So for today this means the data from 6-11-2016 till 6-11-2017.

But my imported data still shows data from the weeks before that, and i want that data deleted. 

OK no need to delete anything just set a restriction under the Visual/Page or Report filters by dropping your date field in there:

  • You can use relative date filtering like display data For the last 30 days or past calendar week only
  • Advance filtering - display items when the date Is on or after (set date)

Advance FilteringAdvance FilteringRelative FilteringRelative FilteringFilter OptionsFilter Options

 

Hope this helps.

 

Regards

Abduvali

I get what you mean, and i tried it, it works.

But the data is still in my imported data. And i want it deleted...data.png

 

 

 

 

 

 

 

 

 

 

 

Got any ideas on this? (your solution works fine for now btw)

Then just update your SQL query because you can't delete data from Dataset selectively, as Dataset is just a box whatever you put in there will sit there so must be done on query level. In your  SQL query instead of saying DATE >= '01/01/2016' use DATE BETWEEN  '01/01/2016' and  '01/01/2017' that way, you will only have the data within your preferred date range. 

I don't think that you understand my issue that well, so i try to be more clear since it has nothing tod o with my SQL query.

My sql query looks like this now:

WHERE CreatedDateTime >= DATEADD(month,-12,DATEADD(day,DATEDIFF(day,0,GETDATE()),0)) 
AND CreatedDateTime  <=DATEADD(day,DATEDIFF(day,0,GETDATE()),0)

This sql statement gives me the data from last 12 months based on todays date. 

 

Now when i push the refresh button to import the new data, it refreshes all my data, import the new dataset with data from now till 12 months ago. But the data that is older then 12 months ago (which i imported last week) , is still in the dataset. This is what i want te see removed. 

Then just remove second line of code and just keep:

WHERE CreatedDateTime >= DATEADD(month,-12,DATEADD(day,DATEDIFF(day,0,GETDATE()),0)) 

This should resolve your issue!!!

 

 

Regards

Abduvali 

Hi @Abduvali,

 

Instead of using SQL statement, you should also be able to simply use Date.IsInPreviousMonth function(M) in Advanced Editor to import data from now till 12 months ago. Smiley Happy

    #"Filtered Rows" = Table.SelectRows(dbo_DimDate, each Date.IsInPreviousNMonths([FullDateAlternateKey], 12))
in
    #"Filtered Rows"

filter.PNG

 

Regards

@v-ljerr-msft,

 

Thank you =D Will try it out sometime!!!

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.