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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Anonymous
Not applicable

Best way to lookup condition of machine based on date & time

About me: I'm a Powert BI newbie but I have a moderate amout of experience in Tableau. Please be patient with me.  Thanks.

 

What I'm trying to do: my objective is to trend the operating temperatures of a machine but I'm only interested in those temperatures when the machine is in a certain configuration.  I have a few hundered thousand lines of data and two seperate tables in Excel.  I cannot use the temperatures value to assume a condition because the temperature ranges for each condition sometimes overlap.

 

The first table has a line every time the machine changes condition with a date and time (including seconds).  Sometimes it has a line even when the condition of the machine didnt change.  Here is a sample of the data:

 

TimestampStatus
8/12/18 5:01:34 PMCondition A
8/12/18 5:03:29 PMCondition A
8/12/18 5:31:29 PMCondition B
8/12/18 5:49:29 PMCondition A
8/12/18 6:13:29 PMCondition B
8/12/18 6:31:29 PMCondition A

 

 

The second table has a bunch of timestamps (that rarely match the time stamps in the first table) which show the the machines temperatures at that point in time.  It looks like this:

 

TimestampTemperature
8/12/18 5:18:16 PM382
8/12/18 5:26:57 PM377.06
8/12/18 5:40:04 PM149
8/12/18 6:15:18 PM131
8/12/18 6:36:30 PM128

 

I'm looking for help on the best way to lookup the machine's condition at the timestamp of the temperature so I can ultimately trend the temperatures but only when the machine is in a certain condition.  Any help is appreciated.  Please let me know if you need any more information to assist.  Thanks.

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@Anonymous I'm thinking something like this:

Column =
  VAR __Timestamp = [Timestamp]
  VAR __MaxTimestamp = MAXX(FILTER('StatusTable','StatusTable'[Timestamp]<__Timestamp),'StatusTable'[Timestamp])
RETURN
  MAXX(FILTER('StatusTable',[Timestamp]=__MaxTimestamp),'StatusTable'[Status])


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...

View solution in original post

12 REPLIES 12
Anonymous
Not applicable

Hi @Anonymous 

You can have a preliminary understanding of DAX by following this link . It contains explanations of DAX, video explanations, function introductions, etc., I hope it will be helpful to you.

https://docs.microsoft.com/en-us/dax/

Ailsamsft_0-1629269103997.png

Best Regards

Community Support Team _ Ailsa Tao

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,

WHat exact result do you expect to see in the third column of Table2.  Please show clearly.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

@Ashish_Mathur thanks for the followup question. I am aiming for the third column of table two to show the corresponding condition (condition A, condition B, etc.) of the machine at the timestamp of the respective temperature measurement.  In short, I need to infer from table one what the condition is of the machines is and then transpose that condition to the corresponding temperature.  

 

For simplicity, lets pretend that Condition A = ON and Condition B = OFF.  From Table one, I could derive the following information:

 

FromToMachine Condition
8/12/2018 5:01:34 PM8/12/2018 5:03:28 PMMachine is ON (i.e. condition A)
8/12/2018 5:03:29 PM8/12/2018 5:31:28 PMMachine is ON (i.e., condition B)
8/12/2018 5:31:29 PM8/12/2018 5:49:28 PMMachine is OFF
8/12/2018 5:49:29 PM8/12/2018 6:13:28 PMMachine is ON
8/12/2018 6:13:29 PM8/12/2018 6:31:28 PMMachine is OFF
8/12/2018 6:31:29 PMpresentMachine is ON

 

Now I can take the timestamps in table two and deduce what the condition of the machine is for the timestamps shown:

 

TimestampTemperatureMachine Condition
8/12/18 5:18:16 PM382ON (i.e., condition A)
8/12/18 5:26:57 PM377.06ON
8/12/18 5:40:04 PM149OFF (i.e., condition B)
8/12/18 6:15:18 PM131OFF
8/12/18 6:36:30 PM128ON

 

Does this help show clearly what I am trying to do?  Sorry for the delayed response.  Please let me know if I need to expplain further.  Thanks.

Sorry but i still do not understand your question.  I do not know what is the inout and what is the output you want.  I'm sure someone will understand your question and help you.


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

@Anonymous I'm thinking something like this:

Column =
  VAR __Timestamp = [Timestamp]
  VAR __MaxTimestamp = MAXX(FILTER('StatusTable','StatusTable'[Timestamp]<__Timestamp),'StatusTable'[Timestamp])
RETURN
  MAXX(FILTER('StatusTable',[Timestamp]=__MaxTimestamp),'StatusTable'[Status])


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...
Anonymous
Not applicable

@Greg_Deckler Thanks for the reply.  Like I said in the OP, I am very new to Power BI...I do not [yet] know Dax but I am learning.  Can you help me understand what this code is doing?  I'm trying to reverse engineer it but not having much luck yet.  

@Anonymous Sure:

Column =
  VAR __Timestamp = [Timestamp]
//This gets the Timestamp of the current row in the table.

  VAR __MaxTimestamp = MAXX(FILTER('StatusTable','StatusTable'[Timestamp]<__Timestamp),'StatusTable'[Timestamp])
/* The FILTER statement filters the other table, for rows where the timestamp column in that table is less than the timestamp in the current table. MAXX iterates over this filtered table to determine the maximum value of the timestamp. In essence, this finds the last time just prior to the timestamp in the current row when the machine last changed status and thus this is the timestamp that corresponds to the status of the machine at the timestamp in question. */

RETURN
  MAXX(FILTER('StatusTable',[Timestamp]=__MaxTimestamp),'StatusTable'[Status])
/* Having determined the correct timestamp, we again filter the table but this time for the exact timestamp we found in __MaxTimestamp and use MAXX to simply return the Status column at that timestamp and hence, the Status of the machine in question.*/


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...
Anonymous
Not applicable

@Greg_Deckler sorry for the delayed response.  I wanted to ask one more question about your proposed solution: is it working under the assumption that there are exact matching timestamps between both tables?  This is not the case but I just wanted to verify because I couldnt be 100% sure based on your generous description of the DAX code.

@Anonymous No such assumption. However, you would want this modification just in case there are:

VAR __MaxTimestamp = MAXX(FILTER('StatusTable','StatusTable'[Timestamp]<=__Timestamp),'StatusTable'[Timestamp])


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...
Anonymous
Not applicable

@Greg_Deckler Thank you for the updated DAX.  I'm still trying to figure out how to substitute the correct table names and column names from my spreadsheets into the approriate areas in the code you suggested.  Any recommendations on a good YouTube video for a beginner?  Right now I cannot get the last 

'StatusTable'[Status]

of the RETURN line to populate with the correct table/column.  I'm sure I am just overlooking something but I cannot figure out.  Sorry if this is something obvious...I'm very new to Power BI which--at this point-- is totallly different than Tableau to me.

 

IMG_8444.jpeg 

Anonymous
Not applicable

@Greg_Deckler Please disregard my last comment...somehow I was able to get the correct table/column entered.  I'm still not sure why sometimes they prepopulate as I'm typing and sometimes I have to manually try to enter them.  Guess it's part of the learning curve?!

@Anonymous Sometimes it depends on whether you have the right syntax and are thus in the right "context" to have items pre-populate using type ahead technology.



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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Kudoed Authors