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
heiligbd
Helper I
Helper I

Solve For Previous Transaction Req # W/ Conditions to Find DateDiff Same Column

Good day, this is my first time posting and I am struggling with this particular query.  I have this dataset pictured below in PowerBi which I have ranked by Dest Date&Time grouped by batch. I need to be able to match the previous transaction Req No to the next transaction blank where the product is returned to storage. There can be multiple events of this happening with the same batch hence why I have them ranked by date/time within a particular batch. The info to the right in the image is the just of what I am needing. In the image I have shown that I need to solve for the yellow blanks with the above Req No. 

 

My ultimate goal is to match the req no with the production order with its return to storage transaction and thereby find the difference in time between the two transactions and metric it. However, I don't think I can find the time difference without first creating a unique req no that matches the next transaction.

 

Any help is much appreciated!

 

Sample of Data TableSample of Data Table

 

5 REPLIES 5
heiligbd
Helper I
Helper I

Hi, unfortunately, I don't believe I am able to share a file. Apologies. Any additional help you can provide is much appreciated.

 

heiligbd
Helper I
Helper I

Yea, let me see what I can come up with.

heiligbd
Helper I
Helper I

Thanks for the quick response!

So, I input the query and it didn't fail, but it only returned blanks for all rows instead of any data from Req No.

 

can you share some sample data, either as an excel or as a table that can be copied ?

johnt75
Super User
Super User

Try the below as a calculated column

Previous req no =
IF (
    ISBLANK ( 'Table'[Req no] )
        && 'Table'[Applicable move] = "Good"
        && 'Table'[Movement type] = "Return to storage",
    VAR currentBatch = 'Table'[Batch]
    VAR currentRank = 'Table'[Rank]
    RETURN
        SELECTCOLUMNS (
            CALCULATETABLE (
                TOPN ( 1, 'Table', 'Table'[Rank] ),
                REMOVEFILTERS ( 'Table' ),
                TREATAS (
                    { ( currentBatch, currentRank - 1, "Good", "Production" ) },
                    'Table'[Batch],
                    'Table'[Rank],
                    'Table'[Applicable move],
                    'Table'[Movement type]
                ),
                NOT ISBLANK ( 'Table'[Req no] )
            ),
            "@val", 'Table'[Req no]
        )
)

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!

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.