Forum Discussion

briantc's avatar
briantc
New Member
2 years ago
Solved

Calculate cycle time with transaction data

Hi,  I'm very new to PowerBI and I'm having a problem calculating cycle time using transaction.  This is super simple in Excel, the data includes mainly parts numbers (Container Names) going through different operations (several transaction can happen at each operation) and the transaction date is recorded.  The data is coming from a SSMS server, when it comes in I sort the data by Container number and transaction date to makes this simpler, but one problem is once this data is pulled into table view it's no longer sorted.

My first approach was to create a calculated column to just bring in the transaction date of the most previous transaction, but this is proving to be difficult since the data is not coming in sorted.  So if someone can help me figure out how to bring the data in sorted or a formula to get the last transation data I would be very grateful.

 

A sample of the data is shown below.

 

 

I tried this formula, but it doesn't work since the data isn't coming in sorted.

PreviousDate = CALCULATEMax('aero view_ContainerTxnHistory'[TransactionDate]),
Filter('aero view_ContainerTxnHistory',
EARLIER('aero view_ContainerTxnHistory'[ContainerName]) = 'aero view_ContainerTxnHistory'[ContainerName]
&&
EARLIER('aero view_ContainerTxnHistory'[OperationName])='aero view_ContainerTxnHistory'[OperationName]
&&
EARLIER('aero view_ContainerTxnHistory'[TransactionDate]) <= 'aero view_ContainerTxnHistory'[TransactionDate]))

 

  • Anonymous's avatar
    Anonymous
    2 years ago

    hi, briantc 

    I'm happy to answer your questions. Sorry to hear that you are not sorting when importing data into power BI and it does not work when using calculated columns.  First of all, if the connection method we choose is the Import connection, we can sort the data in Power Query.

    My sample data is as follows:

    In Power BI table view:

    Using Power Query to sort data:

    The result after sorting:

    If the above sorting method helps you, that's great. If you have any questions, please let me know and I will do my best to solve your problem.

     

     

     

    How to Get Your Question Answered Quickly

    If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

    Best Regards

    Jianpeng Li

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

3 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    briantc Looks similar to MTBF essentially. If you can post sample data and expected results could confirm. See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/339586.
    The basic pattern is:
    Column = 
      VAR __Current = [Value]
      VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

      VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
    RETURN
      __Current - __Previous

     

    Otherwise, Sorry, having trouble following, can you post sample data as text and expected output?
    Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

    Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

    The most important parts are:
    1. Sample data as text, use the table tool in the editing bar
    2. Expected output from sample data
    3. Explanation in words of how to get from 1. to 2.

  • Hi,

    Your calculated column formula seems correct.  Just change the sign from <= to >=

  • Anonymous's avatar
    Anonymous
    Not applicable

    hi, briantc 

    I'm happy to answer your questions. Sorry to hear that you are not sorting when importing data into power BI and it does not work when using calculated columns.  First of all, if the connection method we choose is the Import connection, we can sort the data in Power Query.

    My sample data is as follows:

    In Power BI table view:

    Using Power Query to sort data:

    The result after sorting:

    If the above sorting method helps you, that's great. If you have any questions, please let me know and I will do my best to solve your problem.

     

     

     

    How to Get Your Question Answered Quickly

    If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

    Best Regards

    Jianpeng Li

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