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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
StephenK2022
Frequent Visitor

Maximum Time in mins based on date range from slicer

Hi all,

 

First time using this forum so I hope I'm posting in the right place.

 

I am trying to work out how to dynamically change the amount of minutes in a day based on the date range chosen in a slicer. Basically I am looking for the unnaccounted for minutes on machines in our factory.

 

Currently I have set up a column that has all values as 1440 (max minutes in a day) and subtract all the accounted for minutes to work out what is missing - When I change this to run over say a weekend, It is still working out unnaccounted for minutes based on one day. Is there a function where Power BI can work out how many total minutes are available based on the date range in the slicer?

 

Below are my graphs for reference.

 

Over a one day period

StephenK2022_0-1655198047441.png

Over a weekend

StephenK2022_1-1655198123602.png

 

Many Thanks in advance,

Steve

1 ACCEPTED SOLUTION

@StephenK2022 
Yes becuase DATEDIFF return 0 for the same date difference. Please try

Logged mins vs total mins (Total Accounted for Mins minus Average of TOTAL MINUTES) =
VAR FirstDateInFilter =
    MINX (
        ALLSELECTED ( '24hr production report'[Dates] ),
        '24hr production report'[Dates]
    )
VAR LastDateInFilter =
    MAXX (
        ALLSELECTED ( '24hr production report'[Dates] ),
        '24hr production report'[Dates]
    )
VAR TotalMinutes =
    DATEDIFF ( FirstDateInFilter, LastDateInFilter + 1, MINUTE )
VAR AccountedMinutes =
    SUM ( '24hr production report'[Total Accounted for Mins] )
RETURN
    ABS ( TotalMinutes - AccountedMinutes )

View solution in original post

8 REPLIES 8
StephenK2022
Frequent Visitor

Hi @tamerj1 ,

 

Thanks for your reply, 

 

I am using a measure to work out the unaccounted for mins, the problem is that i am using a column with only 1440 in it. So when I change the date I need a function which will change the value to the maximum minutes over that time period - Basically all the bars in the chart should add up to the total minutes over that time period and all should be the exact same height.

 

Logged mins vs total mins (Total Accounted for Mins minus Average of TOTAL MINUTES) =
IF(AVERAGE('24hr production report'[TOTAL MINUTES]) - (SUM('24hr production report'[Total Accounted for Mins]))<0,(AVERAGE('24hr production report'[TOTAL MINUTES]) - (SUM('24hr production report'[Total Accounted for Mins])))*-1,AVERAGE('24hr production report'[TOTAL MINUTES]) - (SUM('24hr production report'[Total Accounted for Mins])))
 
StephenK2022_0-1655200900324.png

 

@StephenK2022 

Is the date slicer from the same table?

@tamerj1 

 

Yes - It is the "Dates" column in the photo.

 

Thanks

@StephenK2022 

Ok Please try

Logged mins vs total mins (Total Accounted for Mins minus Average of TOTAL MINUTES) =
VAR FirstDateInFilter =
    MINX (
        ALLSELECTED ( '24hr production report'[Dates] ),
        '24hr production report'[Dates]
    )
VAR LastDateInFilter =
    MAXX (
        ALLSELECTED ( '24hr production report'[Dates] ),
        '24hr production report'[Dates]
    )
VAR TotalMinutes =
    DATEDIFF ( FirstDateInFilter, LastDateInFilter, MINUTE )
VAR AccountedMinutes =
    SUM ( '24hr production report'[Total Accounted for Mins] )
RETURN
    ABS ( TotalMinutes - AccountedMinutes )

@tamerj1 

 

Thanks very much, this worked for date ranges over 2 days, however now when we look over one day we are getting this:

 

StephenK2022_1-1655205460441.png

Over a longer time period:

StephenK2022_2-1655205585083.png

I'm guessing it is an issue due to "first date in filter" and "last date in filter" being the same value?

 

Thanks again

 

@StephenK2022 
Yes becuase DATEDIFF return 0 for the same date difference. Please try

Logged mins vs total mins (Total Accounted for Mins minus Average of TOTAL MINUTES) =
VAR FirstDateInFilter =
    MINX (
        ALLSELECTED ( '24hr production report'[Dates] ),
        '24hr production report'[Dates]
    )
VAR LastDateInFilter =
    MAXX (
        ALLSELECTED ( '24hr production report'[Dates] ),
        '24hr production report'[Dates]
    )
VAR TotalMinutes =
    DATEDIFF ( FirstDateInFilter, LastDateInFilter + 1, MINUTE )
VAR AccountedMinutes =
    SUM ( '24hr production report'[Total Accounted for Mins] )
RETURN
    ABS ( TotalMinutes - AccountedMinutes )

@tamerj1 

 

That seems to have done the trick - Thank you so much, this will be very helpful.

 

I wil run a few more tests just to make sure and then I can accept as solution for you.

 

Thanks again

tamerj1
Super User
Super User

Hi @StephenK2022 

Nice chart! 
It seems you are utilizing calculated columns which cannot be dynamic. You need to use measures instead. Please provide more details and a sample data along with the expected results.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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