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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
MStark
Helper III
Helper III

Index Countif

How can I create the LIne_NO in Power Query? Its counting what number time these 2 columns came up so far with the same data. Notice the $D$1:D2 and $C$1:C2 which causes it to start counting from the top but to only count up until the current line

 

MStark_0-1713202756045.png

 

Any assistance would be appreciated. Thanks!!

1 ACCEPTED SOLUTION
dufoq3
Super User
Super User

Hi @MStark,

you can use Group By with Add Index


Result:

dufoq3_0-1713205215514.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtY3tNQ3MjAyUdJRMlSK1YlWMtI3skAVQVZjRK5ILAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, LOCATION_ID = _t]),
    GroupedRows = Table.Group(Source, {"Date", "LOCATION_ID"}, {{"All", each Table.AddIndexColumn(_, "LINE_NO",1,1,Int64.Type), type table [Date=nullable text, LOCATION_ID=nullable text]}}),
    All = Table.Combine(GroupedRows[All])
in
    All

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

5 REPLIES 5
dufoq3
Super User
Super User

Hi @MStark,

you can use Group By with Add Index


Result:

dufoq3_0-1713205215514.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtY3tNQ3MjAyUdJRMlSK1YlWMtI3skAVQVZjRK5ILAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, LOCATION_ID = _t]),
    GroupedRows = Table.Group(Source, {"Date", "LOCATION_ID"}, {{"All", each Table.AddIndexColumn(_, "LINE_NO",1,1,Int64.Type), type table [Date=nullable text, LOCATION_ID=nullable text]}}),
    All = Table.Combine(GroupedRows[All])
in
    All

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

@dufoq3 This works!! Thank you so much!

 

Can you explain what what the query is doing so I understand how its working?

During grouping it adds index column called LINE NO into inner table.

 

dufoq3_0-1713331899252.png

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Very Cool! Thank you so much @DU !!!

Enjoy 😉


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Top Solution Authors
Top Kudoed Authors