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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
maxesse
Regular Visitor

Calculate amount of time with motion sensors triggered

Hi there, I'm trying to solve a problem with Power BI, which involves summing up how long was the motion sensor triggered in each room. Ideally, what I'd try to do is to do a datediff from the first 'motion detected' event until the corresponding 'no motion detected' for the same room, and sum them all up, but I'm pretty new to Power BI and I got stumped.

 

Here's a screenshot of what the data looks like:

 

Screenshot 2018-08-02 at 15.23.45.png

I'd appreciate any pointers, thanks a lot,

Max

 

3 REPLIES 3
Greg_Deckler
Community Champion
Community Champion

This is a problem that involves EARLIER. Take a look at this article...See my article on Mean Time Before Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395...

 

Also, you might have some luck with these two quick measures that I created for dealing with durations/aggregations of time:

 

https://community.powerbi.com/t5/Quick-Measures-Gallery/Periodic-Billing/m-p/409365

 

https://community.powerbi.com/t5/Quick-Measures-Gallery/Open-Tickets/m-p/409364

 

If none of that helps, please post sample/example data that can be copied and pasted. 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



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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Thanks a lot Greg, should have read the topic you pointed out before pasting a screenshot. I'm going to read the docs on EARLIER now 🙂

 

This is a portion of my data, if it helps:

 

Sensor IDSensor NameSensor TypeValueProcessed Time
BedroomSensormotionBedroom Sensormotionno motion detected01/08/2018 22:54:38
BedroomSensormotionBedroom Sensormotionmotion detected01/08/2018 22:54:38
BedroomSensormotionBedroom Sensormotionmotion detected01/08/2018 22:55:41
BedroomSensormotionBedroom Sensormotionno motion detected01/08/2018 22:56:06
BedroomSensormotionBedroom Sensormotionmotion detected01/08/2018 22:56:13
BedroomSensormotionBedroom Sensormotionno motion detected01/08/2018 22:56:26
BedroomSensormotionBedroom Sensormotionmotion detected01/08/2018 22:57:57
BedroomSensormotionBedroom Sensormotionno motion detected01/08/2018 22:58:14
BedroomSensormotionBedroom Sensormotionmotion detected01/08/2018 23:00:51
StudioSensormotionStudio Sensormotionmotion detected01/08/2018 23:01:00
BedroomSensormotionBedroom Sensormotionno motion detected01/08/2018 23:01:07
BedroomSensormotionBedroom Sensormotionmotion detected01/08/2018 23:01:12
StudioSensormotionStudio Sensormotionno motion detected01/08/2018 23:01:20
BedroomSensormotionBedroom Sensormotionno motion detected01/08/2018 23:02:12
BedroomSensormotionBedroom Sensormotionmotion detected01/08/2018 23:02:13
powerMeterBedroom Lampspower0.001/08/2018 23:02:24
BedroomLampsswitchBedroom Lampsswitchoff01/08/2018 23:02:24
BedroomLampsswitchBedroom Lampsswitchoff01/08/2018 23:02:24
BedroomSensormotionBedroom Sensormotionno motion detected01/08/2018 23:02:26
BedroomSonosswitchBedroom Sonosswitchoff01/08/2018 23:04:52
BedroomSonosswitchBedroom Sonosswitchon01/08/2018 23:04:53
BedroomSensormotionBedroom Sensormotionmotion detected01/08/2018 23:06:07
BedroomSensormotionBedroom Sensormotionno motion detected01/08/2018 23:06:35
BedroomSensormotionBedroom Sensormotionmotion detected01/08/2018 23:25:15
BedroomSensormotionBedroom Sensormotionno motion detected01/08/2018 23:25:30
BedroomSensormotionBedroom Sensormotionmotion detected01/08/2018 23:25:55
BedroomSensormotionBedroom Sensormotionno motion detected01/08/2018 23:26:07
BedroomSensormotionBedroom Sensormotionmotion detected01/08/2018 23:31:02
BedroomSensormotionBedroom Sensormotionno motion detected01/08/2018 23:31:27
BedroomSensormotionBedroom Sensormotionmotion detected01/08/2018 23:31:45
BedroomSensormotionBedroom Sensormotionno motion detected01/08/2018 23:31:58
BedroomSensormotionBedroom Sensormotionmotion detected01/08/2018 23:32:18
BedroomSensormotionBedroom Sensormotionno motion detected01/08/2018 23:32:32
BedroomSensormotionBedroom Sensormotionmotion detected01/08/2018 23:32:59
BedroomSensormotionBedroom Sensormotionno motion detected01/08/2018 23:33:10
BedroomSensormotionBedroom Sensormotionmotion detected01/08/2018 23:33:33

Hi @maxesse,

In your scenario, you need to do a datediff from the first 'motion detected' event until the corresponding 'no motion detected' for the same room, and sum them all up. In the following screenshot, get the datediff of two date in blue/red/black/green line, then sum them up. But there is no regular rule to identify the next date of  'no motion detected', so it's hard to get the result using DAX.

 
1.GIF

 

Thanks,
Angelia

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors