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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Calculate difference in running hours for an asset over a period of time

need a way to calculate the difference between two running hours values over a period of time

The period of time will be controlled with a slicer (which is no problem)

here is the data

Capture.PNG

1 ACCEPTED SOLUTION


@Anonymous wrote:

I want a table that calculates the difference in running hours for a period of time for a list of counter-keys

The period of time is set dynamicly with a slicer

does that make more sense?


Yes. that helps. See if the following works for you:

 

Hours Difference Between Dates = 
VAR TheFirstAmount =
    CALCULATE(
        MIN(Metrics[Running Hours]),
        FILTER(
            'Date',
            MIN(Metrics[Reading Date]) >= FIRSTDATE(ALLSELECTED('Date'[Date]))
        )
    )
VAR TheLastAmount =
    CALCULATE(
        MAX(Metrics[Running Hours]),
        FILTER(
            'Date',
            MAX(Metrics[Reading Date]) <= LASTDATE(ALLSELECTED('Date'[Date]))
        )
    )
RETURN
TheLastAmount - TheFirstAmount

 

You can see the PBIX file I worked with here. As far as I can tell, when I move the slicer it pics the dates between the dates in the slicer and calculates the difference. I added a date table since you are working with dates, which you can also see in the PBIX file.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

7 REPLIES 7
edhans
Super User
Super User

I don't see any hours. Just days. Can you clairify, and post data that we can copy into Power BI Desktop to play with vs an image that would require us to retype a lot of data?



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
Anonymous
Not applicable

Counter_keyRunning HoursReading Date
01STSL_CNT48413.31Monday, June 10, 2019
01RTGL_CNT1231Monday, June 10, 2019
01RTGL_CNT1753.7Saturday, August 24, 2019
01STSL_CNT49309.12Thursday, August 29, 2019
01RTGL_CNT1852Thursday, August 29, 2019
01RTGL_CNT1852Thursday, August 29, 2019
01RTGL_CNT1852Sunday, September 15, 2019
01STSL_CNT49521.02Wednesday, September 25, 2019
01RTGL_CNT2214Wednesday, September 25, 2019
01STSL_CNT49953.39Tuesday, October 29, 2019
01RTGL_CNT2482Tuesday, October 29, 2019
01RTGL_CNT2785Monday, December 2, 2019
01RTGL_CNT2786Saturday, December 7, 2019
01STSL_CNT50454.85Tuesday, December 10, 2019
01STSL_CNT50784Thursday, January 2, 2020
01RTGL_CNT2992Thursday, January 2, 2020
Anonymous
Not applicable

need a way to calculate the difference between two running hours values over a period of time for a counter key.

I have a file with 100+ counter keys running hours over 2 years time.

Ok, I see the hours. I still am not clear on what you want. 

 


@Anonymous wrote:

need a way to calculate the difference between two running hours values over a period of time for a counter key.

I have a file with 100+ counter keys running hours over 2 years time.


Let's take the 01RTGL_CNT key.

 

Counter_keyRunning HoursReading Date

01RTGL_CNT12316/10/2019
01RTGL_CNT1753.78/24/2019
01RTGL_CNT18528/29/2019
01RTGL_CNT18528/29/2019
01RTGL_CNT18529/15/2019
01RTGL_CNT22149/25/2019
01RTGL_CNT248210/29/2019
01RTGL_CNT278512/2/2019
01RTGL_CNT278612/7/2019
01RTGL_CNT29921/2/2020

 

What is your expected result? What are the "two running hours values" you are referring to?



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
Anonymous
Not applicable

I want a table that calculates the difference in running hours for a period of time for a list of counter-keys

The period of time is set dynamicly with a slicer

does that make more sense?


@Anonymous wrote:

I want a table that calculates the difference in running hours for a period of time for a list of counter-keys

The period of time is set dynamicly with a slicer

does that make more sense?


Yes. that helps. See if the following works for you:

 

Hours Difference Between Dates = 
VAR TheFirstAmount =
    CALCULATE(
        MIN(Metrics[Running Hours]),
        FILTER(
            'Date',
            MIN(Metrics[Reading Date]) >= FIRSTDATE(ALLSELECTED('Date'[Date]))
        )
    )
VAR TheLastAmount =
    CALCULATE(
        MAX(Metrics[Running Hours]),
        FILTER(
            'Date',
            MAX(Metrics[Reading Date]) <= LASTDATE(ALLSELECTED('Date'[Date]))
        )
    )
RETURN
TheLastAmount - TheFirstAmount

 

You can see the PBIX file I worked with here. As far as I can tell, when I move the slicer it pics the dates between the dates in the slicer and calculates the difference. I added a date table since you are working with dates, which you can also see in the PBIX file.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Please find the formula. For each Asset , taken  Min and Max date. Found there reading. And taken Diff. Not tested. Please, do necessary changes on formula pad

 

Total value = Calculate(
    sumx(  
        ADDCOLUMNS( 
            SUMMARIZE(
                data,
                data[Counter_key],
				"max_date",
				 MAX( 'Date'[Reading Date]),
				 "Min_date",
				 Min( 'Date'[Reading Date]),
                "Max_ID", max(data[Counter_key])
            ),
            "MaXValue",
            calculate(
                Max(data[Running Hours]),
                filter(
                    all(data),
                    data[Counter_key]= [Max_ID] && data[Reading Date]= ([max_date]) )
                ),
			"MinValue",
            calculate(
                Max(data[Running Hours]),
                filter(
                    all(data),
                    data[Counter_key]= [Max_ID] && data[Reading Date]= ([min_date]) )
                )
            )
        ,[MaXValue] -[MinValue]
    )
)

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
https://community.powerbi.com/t5/Community-Blog/Winner-Topper-on-Map-How-to-Color-States-on-a-Map-wi...
https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...
https://community.powerbi.com/t5/Community-Blog/Power-BI-Working-with-Non-Standard-Time-Periods/ba-p...
https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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