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

New calculation based on peak hour usage

Hi Community!

I need help with develop calculation.

I have data which shows item usage (with datetime).

Mockup:

item_idcalculation resultusedatetime
11012019-11-16 12:00:00
11212019-11-16 12:15:00
1612019-11-16 13:50:00
21012019-11-16 08:00:00

 

Calculation is simple avg.

I also have dim table, which help me define HourOfDay based on datetime column.

I wish to create new calculation, which is per item, but only for peak hours. Peak hour is hour which biggest item usage. 

For item_id=1 peak hour = 12, for item_id = 2 -> 08

I manage to define output table which looks like this:

item_idsum_usageHourOfDay
12

12

11

13

21

8

 

I have final table which looks like this:

item_idcalculationcalculation last 20 dayscalculation last 20 days peak hours
199should be 11 
21010should be 10

 

current calculation for last 20 days:

calculation last 20 days =
CALCULATE([calculation];all(Table[datetime]);Table[datetime]>=today()-20)

 

Should I create some kind of virtual aggregated table to get max peak hour and use it in calculation as new variable?

 

Regards!

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @Anonymous ,

If I don't misunderstand, you can try this:

Create measures:

Measure = 
VAR CurrentValue = [sum_usage]
VAR MaxValue =
    CALCULATE (
        MAXX ( 'Table', [sum_usage] ),
        ALLEXCEPT ( 'Table', 'Table'[item_id] )
    )
RETURN
    IF ( CurrentValue = MaxValue, 1 )
calculation last 20 days peak hours = 
CALCULATE (
    DIVIDE (
        CALCULATE (
            SUM ( 'Table'[calculation result] ),
            FILTER ( 'Table', [Measure] <> BLANK () )
        ),
        CALCULATE ( [sum_usage], FILTER ( 'Table', [Measure] <> BLANK () ) )
    ),
    FILTER ( 'Table', 'Table'[datetime] >= TODAY () - 20 )
)

maxx.PNG

PBIX file attached.

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
Icey
Community Support
Community Support

Hi @Anonymous ,

If I don't misunderstand, you can try this:

Create measures:

Measure = 
VAR CurrentValue = [sum_usage]
VAR MaxValue =
    CALCULATE (
        MAXX ( 'Table', [sum_usage] ),
        ALLEXCEPT ( 'Table', 'Table'[item_id] )
    )
RETURN
    IF ( CurrentValue = MaxValue, 1 )
calculation last 20 days peak hours = 
CALCULATE (
    DIVIDE (
        CALCULATE (
            SUM ( 'Table'[calculation result] ),
            FILTER ( 'Table', [Measure] <> BLANK () )
        ),
        CALCULATE ( [sum_usage], FILTER ( 'Table', [Measure] <> BLANK () ) )
    ),
    FILTER ( 'Table', 'Table'[datetime] >= TODAY () - 20 )
)

maxx.PNG

PBIX file attached.

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.