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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
ishade
Regular Visitor

Syntax for TOPN on Source Statement of Power Query

Hi, I would like to setup a report to show data of a 'Event' table of Salesforce (Alexis). 

I tried to prepare a DataFlow but got empty table but columns and got advise from raja1992 of the possible reason. (related link : Empty Columns (no data) of DataFlow of a Salesforc... - Microsoft Fabric Community

 

So I tried to put TOPN option on source statement. Would anyone kindly advise me of how to convert the statement

    

             ソース{[Name = "Event"]}[Data]
 
with putting TOPN so that I can limit the volume to retrieve. ('ソース' means 'source' in Japanese)
 
ishade_0-1759466996140.png

 

 
1 ACCEPTED SOLUTION

hello @ishade 

 

i am not sure but seems the last step is not correct.

 

the M code should put the previous step

Irwan_1-1759726522563.png

you previous step is Navigation (sorry i dont write it in japanese)

Irwan_2-1759726556639.png

 

or else, you can use the ribbon button so you dont have to type the code manually (the selection from ribbon should automatically detect the previous step).

Irwan_3-1759726633039.png

 

Thank you.

View solution in original post

8 REPLIES 8
Praful_Potphode
Resolver II
Resolver II

Based on the screenshot,you will have to expand your data and convert it into a table.

Then You can try below step in power query

Praful_Potphode_1-1759470111577.png

 

the number highlighted shows the number of records you want from the table

 

 

 

danextian
Super User
Super User

hi @ishade 

 

TOPN is a DAX function. You can use Table.FirstN to select the first number of rows. You may also use Table.AddRankColumn to create a rank column then filter the generated rank - this function works similarly with DAX's RANKX. 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Irwan
Super User
Super User

hello @ishade 

 

TOPN is a DAX.

While in your screenshot, it looks like PQ so you need M instead of DAX.

 

in PQ, you can create an index then filter row above certain value of that index.

Irwan_0-1759468100879.png

Irwan_1-1759468175442.png

 

 

Hope this will help.

Thank you.

Hi, Irwan

 

Thanks for your kind reply. I tried to insert step on my Power Query as following; 

ishade_0-1759707779413.png

 

but got error of 'Token Litheral expected'. 

The steps in screenshot are 1. source, 2. navigation, 3. custom (at which I applied "= Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type)"). 

 

I guess main cause of this would be no table at step 2, navigation (on which timeout error happend after 10 minutes.) 

hello @ishade 

 

i think that because it should be dot instead of comma after Int64

Irwan_0-1759708428511.png

 

Thank you.

 

Hi Irwan

Thanks for your kind correction. But I am sorry to report you that it still shows some syntax error as following ;

ishade_0-1759712953935.png

 

hello @ishade 

 

i am not sure but seems the last step is not correct.

 

the M code should put the previous step

Irwan_1-1759726522563.png

you previous step is Navigation (sorry i dont write it in japanese)

Irwan_2-1759726556639.png

 

or else, you can use the ribbon button so you dont have to type the code manually (the selection from ribbon should automatically detect the previous step).

Irwan_3-1759726633039.png

 

Thank you.

Hi Irwan

 

Thanks for your kind comment to put Index with right name of previous step.

But unfortunately, I did not make it since the 3rd. step does not reconignize the 2nd. one.,

which would means I should focus on 2nd. step (yes, navigation) including access right.

 

Anyway, closing this shred for a while, 

I would like to appreciate your valuable time to support this matter. Have a nice day!!!

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.