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
odzelashvili1
Helper I
Helper I

Calculate average of column by date and one more column

Hi PBI community,

 

my table looks like this:

odzelashvili1_1-1630657279156.png

and i want to create a measure, which calculates average [waiting_time] of unique [visit_key] by:

1. [queue_key] = 1 or 14

2. [time_key] = min of the column.

 

In this little example my measure must calculate [waiting_time] for: 

[visit_key] = 88279 [waiting_time] = 125

[visit_key] = 88283 [waiting_time] = 0

[visit_key] = 88290 [waiting_time] = 0

[visit_key] = 88307 [waiting_time] = 0

[visit_key] = 88022 [waiting_time] = 699

which is 164.8

 

Any suggestions?

2 ACCEPTED SOLUTIONS
Jos_Woolley
Solution Sage
Solution Sage

Hi,

Average Waiting Time =
VAR MyTable =
    SUMMARIZE (
        'Table',
        'Table'[visit_key],
        "Min Waiting Time", CALCULATE ( MIN ( 'Table'[waiting_time] ), 'Table'[queue_key] IN { 1, 14 } )
    )
RETURN
    AVERAGEX ( MyTable, [Min Waiting Time] )

Regards

View solution in original post

Jos_Woolley
Solution Sage
Solution Sage

Not sure I've fully grasped the nature of the source data, so you'll need to check this:

Waiting Time For Min Key =
VAR MyTable =
    SUMMARIZE (
        'NewTable',
        NewTable[visit_key],
        "Min Time Key",
            LOOKUPVALUE (
                NewTable[waiting_time],
                NewTable[time_key], CALCULATE ( MIN ( 'NewTable'[time_key] ), 'NewTable'[queue_key] IN { 1, 14 } )
            )
    )
RETURN
    AVERAGEX ( MyTable, [Min Time Key] )

Regards

View solution in original post

7 REPLIES 7
Jos_Woolley
Solution Sage
Solution Sage

Not sure I've fully grasped the nature of the source data, so you'll need to check this:

Waiting Time For Min Key =
VAR MyTable =
    SUMMARIZE (
        'NewTable',
        NewTable[visit_key],
        "Min Time Key",
            LOOKUPVALUE (
                NewTable[waiting_time],
                NewTable[time_key], CALCULATE ( MIN ( 'NewTable'[time_key] ), 'NewTable'[queue_key] IN { 1, 14 } )
            )
    )
RETURN
    AVERAGEX ( MyTable, [Min Time Key] )

Regards

Jos_Woolley
Solution Sage
Solution Sage

Ok, but first can you clarify what happens if there is more than one occurrence of min [time_key] for a given [visit_key]? Which [waiting_time] do we take in that situation? For example, in the below is 50 or 136 to be returned?

 

time_keyvisit_keyvisit_outcome_keyqueue_keywaiting_time
364208831651136
3642088316513350
3666088316513378
38340883165140
383408831651430
38400883165230
384008831632358

 

Regards

Earlier [time_key] cannot be more than one row (with [queue_key] 1 or 14,  

odzelashvili1_0-1630678237982.png

this is possible, but not for min [time_key].

 

 

 

Ilia

Jos_Woolley
Solution Sage
Solution Sage

You're welcome!

Regards

Jos,

 

I have problem 🙂 

 

Using this code, I'm taking Min [waiting time] value in Mytable, which is incorrect, I need to take [waiting_time] by min [time_key].

 

e.i. 

odzelashvili1_0-1630672006948.png

In this case, your code will take 30, Instead of 136, can u modify code?

 

Thanks again 🙂

Jos_Woolley
Solution Sage
Solution Sage

Hi,

Average Waiting Time =
VAR MyTable =
    SUMMARIZE (
        'Table',
        'Table'[visit_key],
        "Min Waiting Time", CALCULATE ( MIN ( 'Table'[waiting_time] ), 'Table'[queue_key] IN { 1, 14 } )
    )
RETURN
    AVERAGEX ( MyTable, [Min Waiting Time] )

Regards

Thank you 🙂

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.