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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Calculate Total time duration for ON/OFF states

Hello All,

 

I have a table where it got date values with every three minutes of intervel.

In that table itself i have a column which gives status of AC whether its ON/OFF.

See the table below.

 

TimeAC Status
11:03:00 AMON
11:06:00 AMOFF
11:09:00 AMON
11:12:00 AMON
11:15:00 AMON
11:18:00 AMON
11:21:00 AMOFF
11:24:00 AMOFF
11:27:00 AMON
11:30:00 AMON
11:33:00 AMON
11:36:00 AMON
11:39:00 AMON
11:42:00 AMON
11:45:00 AMOFF
11:48:00 AMOFF
11:51:00 AMOFF
11:54:00 AMON
11:57:00 AMON
12:00:00 PMON

 

 

Now i would like to calclute the time duration in minutes for the both states that is ON/OFF.

i.e total running time duration for ON status, i.e total running time duration for OFF status,

 

Can any one please suggest me to get this done.

I will be so thankful to you.

 

Thanks,

Mohan V

2 REPLIES 2
CanadaMGB
Frequent Visitor

Assuming your interval is always 3 minutes, you can count the rows in each status, subtract the status count of the first record, and multiple by 3. Try this:

 

ON TEST = 

VAR 
MINDATE = MIN(Table1[time])
VAR
MINCOUNT = COUNTROWS(filter(Table1,Table1[AC Status]="on" && Table1[time] = MINDATE))
VAR
ONCOUNT = COUNTROWS(filter(Table1,Table1[AC Status]="on"))
RETURN
(ONCOUNT-MINCOUNT)*3

If you do want to count the result of the first row, just use the ONCOUNT= line and skip the rest. 

danextian
Super User
Super User

Hi @Anonymous,

 

Are you trying to get the time difference between the current row and the previous row?





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.