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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
olimilo
Continued Contributor
Continued Contributor

[Power Query] How to get the first non-zero value in a table?

Using the sample table below - is it possible to get the first non-zero value using Power Query?

 

I understand I can possibly do this via DAX but there are over 100k rows and it seems wasteful to load that much data into the report so I am taking the PQ route. I also understand, I can possibly use Pivot in this case however, the RN (Row Number) goes as far as RN=39. I'm thinking maybe convert the VAL column to a text column and then merge them into one but how do I make sure I am getting all pivoted VAL columns upon refresh?

 

ID VAL RN
1001404038 2393.64 1
1001459253 562.25 1
1001463837 0 1
1001463837 3252.24 2
1001478049 4606.74 1
1001478049 4601.74 2
1001478049 4601.74 3
1001478049 4601.74 4

 

Output should be like this:

 

1001404038 2393.64 1
1001459253 562.25 1
1001463837 3252.24 2
1001478049 4606.74 1
1 ACCEPTED SOLUTION
Ahmedx
Super User
Super User

and you can useed this code

Screenshot_1.png

 

Table.Group(#"Changed Type", {"ID"}, {{"Count", 
each  Table.FirstN(
 Table.SelectRows(_, each _[VAL] > 0),1)
}})

 

 

View solution in original post

4 REPLIES 4
Ahmedx
Super User
Super User

and you can useed this code

Screenshot_1.png

 

Table.Group(#"Changed Type", {"ID"}, {{"Count", 
each  Table.FirstN(
 Table.SelectRows(_, each _[VAL] > 0),1)
}})

 

 

Ahmedx
Super User
Super User

pls see my video

https://1drv.ms/v/s!AiUZ0Ws7G26Ringrxdxj3drlNpFE?e=8vMDu4

 =Table.Group(#"Changed Type", {"ID"}, {{"Count", 
each  Table.SelectRows(
 Table.AddIndexColumn( Table.SelectRows(_, each _[VAL] > 0),"Indx",1,1), each _[Indx]=1)
}})

 

Ahmedx
Super User
Super User

it's not very clear what you want
explain again and provide an example of the result you want to get

olimilo
Continued Contributor
Continued Contributor

THanks, I've edited the post to show the requested output.

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.