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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
xichiza
Frequent Visitor

Help - Count number of consecutive non null row

I have a very specific request where I need to calculate the number of consecutive non blank row in a certain way : 

- If there are consecutive values whithout blank value -> count = 1

- If there are consecutive values with 1 blank, it shoudl increment the count -> count = 2

Here is what it looks like :

 

xichiza_0-1632726048256.png

Basically, I want to be able to count the number of consecutive non blank value in a row.

 

Hope my request is understable (hard to explain).

 

Thanks for your replies

1 ACCEPTED SOLUTION

@xichiza 
Create a blank Query, go to the Advanced Editor, clear the existing code, and paste the codes give below and follow the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcs0tyMmvTE1V8HRR0lHySswrTSyqBLLcUpOKoEzfxKLkDCDtWFCUmQPmg0S9SvNSwVQOiOdYml5aXAJkBKcWlKTmJqUWKcXqIJluCJTChhVQMIoWI6gwNi2G2LUYo5mKTYshqhYTHA5DxbGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#" " = _t, #"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t, #"(blank).4" = _t, #"(blank).5" = _t, #"(blank).6" = _t, #"(blank).7" = _t, #"(blank).8" = _t]),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    #"Replaced Value" = Table.ReplaceValue(#"Promoted Headers"," ","|",Replacer.ReplaceValue,{"Employee ID", "January", "February", "March", "April", "May", "June", "July", "August", "September"}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Replaced Value", {"Employee ID"}, "Attribute", "Value"),
    #"Grouped Rows" = Table.Group(#"Unpivoted Other Columns", {"Employee ID", "Value"}, {{"Count", each Table.RowCount(_), Int64.Type}},GroupKind.Local),
    #"Removed Columns" = Table.RemoveColumns(#"Grouped Rows",{"Count"}),
    #"Filtered Rows" = Table.SelectRows(#"Removed Columns", each ([Value] = "1")),
    #"Grouped Rows1" = Table.Group(#"Filtered Rows", {"Employee ID"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
    Custom1 = #"Grouped Rows1",
    #"Merged Queries" = Table.NestedJoin(#"Promoted Headers", {"Employee ID"}, Custom1 , {"Employee ID"}, "Custom1", JoinKind.LeftOuter),
    #"Expanded Custom1" = Table.ExpandTableColumn(#"Merged Queries", "Custom1", {"Count"}, {"Count"})
in
    #"Expanded Custom1"

Fowmy_0-1632728369572.png

If you remove the last 3 steps, then you get the following if you need it this way:

Fowmy_1-1632728403178.png

 

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

5 REPLIES 5
xichiza
Frequent Visitor

Awesome ! Thanks a lot for your help ! 

What a nice and quick way to do it !

xichiza
Frequent Visitor

Ok, I have extract some data and create a Power BI report. Can you please tell me if it is ok for you ?

https://www.transfernow.net/dl/20210927W5Sq0Ohm/iPmgUTcn

Thanks again 

xichiza
Frequent Visitor

@Fowmy  thanks for your reply .

 

Unfortunaly, I cant share the data as there are confidentials however please find here a set of data and the results I need  ("count" column). Better in Dax but if you have a solution using Power Query I will take it too 🙂

 

Employee IDJanuaryFebruaryMarchAprilMayJuneJulyAugustSeptemberCount
Employee 111111    1
Employee 2 1111 1  2
Employee 31  11 1 14
Employee 41111111111

@xichiza 
Create a blank Query, go to the Advanced Editor, clear the existing code, and paste the codes give below and follow the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcs0tyMmvTE1V8HRR0lHySswrTSyqBLLcUpOKoEzfxKLkDCDtWFCUmQPmg0S9SvNSwVQOiOdYml5aXAJkBKcWlKTmJqUWKcXqIJluCJTChhVQMIoWI6gwNi2G2LUYo5mKTYshqhYTHA5DxbGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#" " = _t, #"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t, #"(blank).4" = _t, #"(blank).5" = _t, #"(blank).6" = _t, #"(blank).7" = _t, #"(blank).8" = _t]),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    #"Replaced Value" = Table.ReplaceValue(#"Promoted Headers"," ","|",Replacer.ReplaceValue,{"Employee ID", "January", "February", "March", "April", "May", "June", "July", "August", "September"}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Replaced Value", {"Employee ID"}, "Attribute", "Value"),
    #"Grouped Rows" = Table.Group(#"Unpivoted Other Columns", {"Employee ID", "Value"}, {{"Count", each Table.RowCount(_), Int64.Type}},GroupKind.Local),
    #"Removed Columns" = Table.RemoveColumns(#"Grouped Rows",{"Count"}),
    #"Filtered Rows" = Table.SelectRows(#"Removed Columns", each ([Value] = "1")),
    #"Grouped Rows1" = Table.Group(#"Filtered Rows", {"Employee ID"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
    Custom1 = #"Grouped Rows1",
    #"Merged Queries" = Table.NestedJoin(#"Promoted Headers", {"Employee ID"}, Custom1 , {"Employee ID"}, "Custom1", JoinKind.LeftOuter),
    #"Expanded Custom1" = Table.ExpandTableColumn(#"Merged Queries", "Custom1", {"Count"}, {"Count"})
in
    #"Expanded Custom1"

Fowmy_0-1632728369572.png

If you remove the last 3 steps, then you get the following if you need it this way:

Fowmy_1-1632728403178.png

 

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Fowmy
Super User
Super User

@xichiza 

Can share the data that you used in your visual? you paste it directly with your reply. And, how do you want the result to be shown? Are you fine with Power Query solution as well?


Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.