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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
briantc
New Member

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.

 

briantc_1-1706914880694.png

 

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]))

 

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

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:

1.png

In Power BI table view:

2.png

Using Power Query to sort data:

3.png

The result after sorting:

4.png

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.

View solution in original post

3 REPLIES 3
v-jianpeng-msft
Community Support
Community Support

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:

1.png

In Power BI table view:

2.png

Using Power Query to sort data:

3.png

The result after sorting:

4.png

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.

Ashish_Mathur
Super User
Super User

Hi,

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


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Greg_Deckler
Super User
Super User

@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/3395....
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.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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