Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

How to calculate the difference between two points that do not overlap

Hey there community, I have no idea how to search for this problem, so if there is a post out there please let me know as I had no luck. 
I basically have data that looks like the below, I basically need the delta beween top and bottom, so [top] - [bot], the issue is that most of the points are not along the same x data point, so I cant simply do [top] - [bot].

 

My thought to get this to work is this to connect each point, and artifically create points (so interpolate), it could be both bot and top or just one of them. With this logic I should be able to do [top] - [bot]. 

 

I was thinking of a y = mx approach, for the [bot] line and then I can calculate the intercept between a [top] point and the line [bot]

 

I literally have millions of rows, and not sure if this should be a DAX measure (likely Power Query?) and more importantly if it can actually be done?


Data structure looks like:

 

x-axiselevationPoint Type
1082066.225142.5top
1082067.689142top
1082068.641141.95top
1082071.206142.15top
1082071.645141.95top
1082071.868142top
1082073.186142.35top
1082077.261104.35bot
1082078.316226.8top
1082084.402332.8top
1082089.316334top
1082091.509297.1top
1082101.344188.75top
1082105.961134.15bot
1082111.167210.1top
1082111.271134.8bot
1082115.266125.55bot
1082118.76688.5bot
1082120.923177.65top
1082122.42895.75bot
1082130.44782.05bot
1082130.749184.35top
1082134.674184top
1082140.66983.35bot
1082144.411188.65top
1082150.26976.05bot
1082154.233192.25top
1082160.71559.15bot
1082163.982182.2top
1082171.22447.55bot
1082173.503183.95top
1082181.5846.55bot
1082183.262179.8top
1082191.59154.45bot
1082193.012175.5top
1082201.26642.75bot
1082202.758174.35top
1082211.81954.05bot

 

 

 

  • Hi Anonymous ,

     

    To calculate the difference between non-overlapping top and bot elevation points, you need to interpolate one or both datasets so that they align on the same x-axis. Since the x-values are not matched across the two elevation types, you can’t simply subtract [top] - [bot]. Instead, in Power Query, start by extracting a master list of unique x-values across both top and bot data using:

    CombinedX = List.Distinct(YourTable[x-axis])
    

    Then split your original table into two separate queries—one for top and one for bot—like this:

    TopTable = Table.SelectRows(YourTable, each [Point Type] = "top")
    BotTable = Table.SelectRows(YourTable, each [Point Type] = "bot")
    

    Now you need to reindex and interpolate each table to fill in missing x-axis values. To do this, perform a left join from the CombinedX list to each of the top and bot tables. This will give you rows with null elevations where values are missing. Then sort the joined table by x, add an index, and for rows with missing elevations, identify the previous and next known values and interpolate using this formula:

    Interpolated = y1 + (x - x1) * ((y2 - y1) / (x2 - x1))
    

    Where x is the missing point, and (x1, y1) and (x2, y2) are the bounding known data points. You can extract these by grouping and adding custom columns with List.FirstN and List.Skip operations or using buffer + index tricks. Once both top and bot tables are interpolated with the same set of x-values, merge them together on x and compute the difference:

    Delta = [Top Elevation] - [Bot Elevation]
    

    This will give you the vertical gap between the two elevation lines at every point, even when the original data did not overlap. If you're dealing with millions of rows, do this logic inside Power Query rather than DAX to avoid performance bottlenecks.

     

    Best regards,

5 Replies

  • Hi Anonymous ,

     

    To calculate the difference between non-overlapping top and bot elevation points, you need to interpolate one or both datasets so that they align on the same x-axis. Since the x-values are not matched across the two elevation types, you can’t simply subtract [top] - [bot]. Instead, in Power Query, start by extracting a master list of unique x-values across both top and bot data using:

    CombinedX = List.Distinct(YourTable[x-axis])
    

    Then split your original table into two separate queries—one for top and one for bot—like this:

    TopTable = Table.SelectRows(YourTable, each [Point Type] = "top")
    BotTable = Table.SelectRows(YourTable, each [Point Type] = "bot")
    

    Now you need to reindex and interpolate each table to fill in missing x-axis values. To do this, perform a left join from the CombinedX list to each of the top and bot tables. This will give you rows with null elevations where values are missing. Then sort the joined table by x, add an index, and for rows with missing elevations, identify the previous and next known values and interpolate using this formula:

    Interpolated = y1 + (x - x1) * ((y2 - y1) / (x2 - x1))
    

    Where x is the missing point, and (x1, y1) and (x2, y2) are the bounding known data points. You can extract these by grouping and adding custom columns with List.FirstN and List.Skip operations or using buffer + index tricks. Once both top and bot tables are interpolated with the same set of x-values, merge them together on x and compute the difference:

    Delta = [Top Elevation] - [Bot Elevation]
    

    This will give you the vertical gap between the two elevation lines at every point, even when the original data did not overlap. If you're dealing with millions of rows, do this logic inside Power Query rather than DAX to avoid performance bottlenecks.

     

    Best regards,

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous,

    Thanks for reaching out to the Microsoft fabric community forum.

    It looks like you are facing difficulties with calculating the difference between two points. As DataNinja777 have already responded to your query, kindly go through his response and check if it solves your issue.

     

    I would also take a moment to thank DataNinja777, for actively participating in the community forum and for the solutions you’ve been sharing in the community forum. Your contributions make a real difference.

     

    If I misunderstand your needs or you still have problems on it, please feel free to let us know.  

    Best Regards,
    Hammad.
    Community Support Team

     

    If this post helps then please mark it as a solution, so that other members find it more quickly.

    Thank you.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Anonymous,

      As we haven’t heard back from you, so just following up to our previous message. I'd like to confirm if you've successfully resolved this issue or if you need further help.

      If yes, you are welcome to share your workaround and mark it as a solution so that other users can benefit as well. If you find a reply particularly helpful to you, you can also mark it as a solution.


      If you still have any questions or need more support, please feel free to let us know. We are more than happy to continue to help you.
      Thank you for your patience and look forward to hearing from you.

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi Anonymous,

        I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution so that other community members can find it easily.


        Thank you.