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
Anonymous
Not applicable

Specific number of latest rows from SQL Server with Power Query

Being relatively new in Power BI Desktop I have the following scenario from a client:

 

We have some sensors that send data to an Azure SQL Database constantly. About 300 rows added in the database per day.

All the data are displayed in a report through Direct Query and page autorefresh. For the moment a particular visual (Line Chart), displays ALL the data from the database.

 

I want to have after each refresh the last 500 rows of the database.

Is this possible?

 

Thanks in advance

1 ACCEPTED SOLUTION

My bad, didn't read your question thoroughly!! Are you using a SQL Statement to query the source database? If so, you can try the following in your SQL Statement:

let
    Source = Sql.Database(Server, Database, [Query="SELECT TOP (500) Columns FROM Table ORDER BY DateKey DESC"])
in
    Source

Hope this answer solves your problem!
If you need any additional help please @ me in your reply.
If my reply provided you with a solution, please consider marking it as a solution ✔️ or giving it a kudoe 👍
Thanks!

You can also check out my LinkedIn!

Best regards,
Gonçalo Geraldes

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

@goncalogeraldes 

 

Thanks for your immediate answer, but the 'keep rows' function, as Power Query message displays, is not supported in imported data through DirectQuery.

 

 

My bad, didn't read your question thoroughly!! Are you using a SQL Statement to query the source database? If so, you can try the following in your SQL Statement:

let
    Source = Sql.Database(Server, Database, [Query="SELECT TOP (500) Columns FROM Table ORDER BY DateKey DESC"])
in
    Source

Hope this answer solves your problem!
If you need any additional help please @ me in your reply.
If my reply provided you with a solution, please consider marking it as a solution ✔️ or giving it a kudoe 👍
Thanks!

You can also check out my LinkedIn!

Best regards,
Gonçalo Geraldes

Anonymous
Not applicable

@goncalogeraldes 

 

Where should I put this snippet? I'm rather beginner... 😟

Go to the "Transform Data" option in the Home tab and in the new window select the table you need to query. After this step you need to open the "Advanced Editor" and paste the code.

 

goncalogeraldes_0-1649412377960.png

 

Please be aware that, if you have applied transformations to your data in Power Query, the code I've provided will discard those changes. You need to adapt the code to your requirements, namely the Server and Database names and the Column and Table names on the Query!

 

goncalogeraldes
Super User
Super User

Hello there @Anonymous ! You can go to Power Query ("Transform Data") and choose the "Keep Rows" options in the "Home" tab and then the "Keep Bottom Rows".

 

goncalogeraldes_0-1649409700284.png

 

In the pop-up window just insert the number of rows you want to keep, in your case 500. Click "Ok" and then "Close & Apply" and you are good to go!

 

Hope this answer solves your problem!
If you need any additional help please @ me in your reply.
If my reply provided you with a solution, please consider marking it as a solution ✔️ or giving it a kudoe 👍
Thanks!

You can also check out my LinkedIn!

Best regards,
Gonçalo Geraldes

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.