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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
DontLikeMondays
Regular Visitor

Solution required for finding 'data gap' in table and adding a new row showing the correct status

Hi all,

I am in need of some help please.

We have a table where we log PC 1 and PC 2 operational status.

We have Columns: PC Name (PC01, PC02), status (Available, Unavailable or Working), Start Time (Date/Time) and End Time (Date/Time).

I need to find the 'data gaps' where the Start Time of a new status does not equal the End Time of the last status of that PC,

then add a new row to the table showing the 'data gap' period as status 'Unavailable'.

 

DontLikeMondays_1-1733972915272.png

 

The above is the table we currently have and highlighted in red is the 'data gap'.

 

DontLikeMondays_2-1733973075739.png

 

The above is what i need to achieve, an added row with the 'data gap' showing in status 'Unavailable' as highlighted in green.

 

Any help is very much appreciated 🙂

Thanks 🙂

 

1 ACCEPTED SOLUTION
v-saisrao-msft
Community Support
Community Support

Hi @DontLikeMondays 

Thanks for Posting in Microsoft forum Community. 

 

As per the Query you mentioned for Solution required for finding 'data gap' in table and adding a new row showing the correct status. The provided DAX query is designed to find gaps in a table's data where the StartTime of a new row does not immediately follow the EndTime of the previous row for the same PC Name. It then creates new rows to fill those gaps, assigning them the status "Ideal". Here's a breakdown of how the code works: 

 

Step1: First it Creates a new intermediate table (GapRows) that includes additional calculated columns: 
VAR GapRows = 

    ADDCOLUMNS( 

        'Data',  // Table name is 'Data' 

        "NextStartTime", 

        CALCULATE( 

            MIN('Data'[StartTime]),  // Get the next StartTime for the same PC Name 

            FILTER( 

                'Data',  // Filtering to get the next row 

                'Data'[PC Name] = EARLIER('Data'[PC Name]) && 

                'Data'[StartTime] > EARLIER('Data'[StartTime])  // Ensure we only look ahead 

            ) 

        ), 

        "CurrentEndTime", 'Data'[EndTime]  // Rename existing EndTime to avoid conflict 

    ) 

 
Step2: Identifies rows where there is a gap between the CurrentEndTime of a row and the NextStartTime of the next row for the same PC Name: 

VAR IdealRows = 

    SELECTCOLUMNS( 

        FILTER( 

            GapRows, 

            NOT ISBLANK([NextStartTime]) && [CurrentEndTime] < [NextStartTime]  // Detect gaps 

        ), 

        "PC Name", [PC Name], 

        "Status", "Ideal",  // Add status as "Ideal" for the gap rows 

        "StartTime", [CurrentEndTime],  // Start time of the "Ideal" row is the current EndTime 

        "EndTime", [NextStartTime]  // End time of the "Ideal" row is the next StartTime 

    ) 

 

 
Step3: Combine Original and Gap Rows: 

                    RETURN 

                           UNION( 

                            'Data',  // Combine original data 

                                IdealRows  // Combine with the newly generated Ideal rows 

                                     ) 

Using the above code, I obtained the expected output. I opted to use "Ideal" instead of "Unavailable" to enhance clarity and understanding. 

vsaisraomsft_3-1734067843916.png

 

By utilizing conditional formatting, I was able to highlight the desired results. 

vsaisraomsft_1-1734067360697.png

 

 Using the Background Color feature, I set a rule to get the desired results. 

vsaisraomsft_2-1734067360698.png

If this post helps, then please give us Kudos and consider Accept it as a solution to help the other members find it more quickly. 

Thank you.

 

View solution in original post

10 REPLIES 10
v-saisrao-msft
Community Support
Community Support

hi @DontLikeMondays 

Just following up as we haven’t received a response to our previous message. We hope your issue has been resolved.

If the solution we provided has worked for you, kindly mark it as the accepted solution.

Thank you for being a valued member of the Microsoft Fabric Community Forum!

v-saisrao-msft
Community Support
Community Support

Hi @DontLikeMondays 

Thanks for Posting in Microsoft forum Community. 

 

As per the Query you mentioned for Solution required for finding 'data gap' in table and adding a new row showing the correct status. The provided DAX query is designed to find gaps in a table's data where the StartTime of a new row does not immediately follow the EndTime of the previous row for the same PC Name. It then creates new rows to fill those gaps, assigning them the status "Ideal". Here's a breakdown of how the code works: 

 

Step1: First it Creates a new intermediate table (GapRows) that includes additional calculated columns: 
VAR GapRows = 

    ADDCOLUMNS( 

        'Data',  // Table name is 'Data' 

        "NextStartTime", 

        CALCULATE( 

            MIN('Data'[StartTime]),  // Get the next StartTime for the same PC Name 

            FILTER( 

                'Data',  // Filtering to get the next row 

                'Data'[PC Name] = EARLIER('Data'[PC Name]) && 

                'Data'[StartTime] > EARLIER('Data'[StartTime])  // Ensure we only look ahead 

            ) 

        ), 

        "CurrentEndTime", 'Data'[EndTime]  // Rename existing EndTime to avoid conflict 

    ) 

 
Step2: Identifies rows where there is a gap between the CurrentEndTime of a row and the NextStartTime of the next row for the same PC Name: 

VAR IdealRows = 

    SELECTCOLUMNS( 

        FILTER( 

            GapRows, 

            NOT ISBLANK([NextStartTime]) && [CurrentEndTime] < [NextStartTime]  // Detect gaps 

        ), 

        "PC Name", [PC Name], 

        "Status", "Ideal",  // Add status as "Ideal" for the gap rows 

        "StartTime", [CurrentEndTime],  // Start time of the "Ideal" row is the current EndTime 

        "EndTime", [NextStartTime]  // End time of the "Ideal" row is the next StartTime 

    ) 

 

 
Step3: Combine Original and Gap Rows: 

                    RETURN 

                           UNION( 

                            'Data',  // Combine original data 

                                IdealRows  // Combine with the newly generated Ideal rows 

                                     ) 

Using the above code, I obtained the expected output. I opted to use "Ideal" instead of "Unavailable" to enhance clarity and understanding. 

vsaisraomsft_3-1734067843916.png

 

By utilizing conditional formatting, I was able to highlight the desired results. 

vsaisraomsft_1-1734067360697.png

 

 Using the Background Color feature, I set a rule to get the desired results. 

vsaisraomsft_2-1734067360698.png

If this post helps, then please give us Kudos and consider Accept it as a solution to help the other members find it more quickly. 

Thank you.

 

danextian
Super User
Super User

Hi @DontLikeMondays 

 

Please post a workable sample data and not an image. A link to an Excel file or a sanitized copy of your pbix will do.





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.

Hi @danextian 

Thanks for your prompt reply.

Please find example pbix file here:

https://www.dropbox.com/scl/fi/7pf2fyym6nmbn09r8u3cm/PC-Status-Log.pbix?rlkey=i96rp5xz2sxvzsnjc4ai6p...

 

Many thanks in advance 

 

Hi @danextian 

I am sorry, i had used the incorrect file.

Please find the correct file here: 

https://www.dropbox.com/scl/fi/jgc9yyyfanbd4b4qb8n3c/PC-Status-LogV2.pbix?rlkey=pi5eg23cirxp7wg0om4o...

 

Thanks 

I had a look at your sample data but there isnt any row where previous endtime <> current start time other than the first row per pc

danextian_0-1733979745340.png

 





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.

Hi @DontLikeMondays 

 

Firs you need to identify which rows in your data has a gap by accessing the data from the immediately preceding row based on a datetime column

danextian_2-1733982668829.png

 

danextian_1-1733982653539.png

Another table is creating filtering the gap rows and assigning a different value to Status and EndTime. It is then combined with the original table without the extra columns.

danextian_0-1733982634128.png

Please note that when using UNION, the columns must match in both number and order at the time of creation. Altering the column order after the calculated table has been created will lead to incorrect results. In such cases, the table must be deleted and recreated to ensure accuracy.

 

This could have been done using Power Query but will involve a lot of merging and can be slow with large datasets.





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.

Thank you @danextian 

i will try your solution and see if i can get it working.

Thanks 🙂

Hi @DontLikeMondays 

Did this work for you?





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.

Hi @danextian 
Sorry my late response, I have not had much time working on this.

It worked fine with the sample data, but it's not working on our production data.

Something is going wrong with the 'previous end time' calculation.. 

I hope to get some time in the new year to look into it.

Thank you for your help 🙂

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors