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
Liwi
Frequent Visitor

Average Time difference

Hi All,

I am failing to figure out how to calculate the average difference between moves of product

- within one area ( average of max date - min date for all IDs )

- between different areas ( average (max date of one area - min of other area) for all IDs

 

ie

IDAreaDate
A101/01/2018
A202/01/2018
A305/01/2018
A306/01/2018
B105/01/2018
B206/01/2018
B308/01/2018
B310/01/2018
B311/01/2018

 

- Avg time for moves in Area 3 - ID A = 1, ID B = 3; AVG = 2

- Avg Time between area 1 & 3 - ID A = 5, ID B = 6; AVG = 5.5

 

I have tried to use measure with SUMMARIZE but hit a wall.

Appreciate if someone could point me in right direction

 

Thank you in advance

7 REPLIES 7
Greg_Deckler
Super User
Super User

I tried to follow this, but not having much success. The following is based upon the description of average of max - min of all ids

 

Product Within One Area = 
VAR myTable = SUMMARIZE(Areas,[ID],[Area],"Max",MAX(Areas[Date]))
VAR myAverage = AVERAGEX(myTable,[Max])
VAR myMin = CALCULATE(MIN(Areas[Date]),ALL(Areas))
RETURN myAverage - myMin

UPDATE: OK, after re-reading this and then realizing that your dates were not US date format and switching that up, try this one instead:

 

Product Within One Area = 
VAR myTable = SUMMARIZE(Areas,[ID],[Area],"Max",MAX(Areas[Date])-MIN(Areas[Date]))
RETURN AVERAGEX(myTable,[Max])

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Liwi

 

What is the format of your Output?? Card Visual or Table

 

For individual calculations you can use MEASURES like following

 

Avg time for moves in Area 3 =
VAR Cat_A =
    CALCULATE ( MAX ( Table1[Date] ), Table1[ID] = "A", Table1[Area] = 3 )
        - CALCULATE ( MIN ( Table1[Date] ), Table1[ID] = "A", Table1[Area] = 3 )
VAR Cat_B =
    CALCULATE ( MAX ( Table1[Date] ), Table1[ID] = "B", Table1[Area] = 3 )
        - CALCULATE ( MIN ( Table1[Date] ), Table1[ID] = "B", Table1[Area] = 3 )
RETURN
    ( Cat_A + Cat_B )
        / 2

 

Avg time between Area 1 & 3 =
VAR Cat_A =
    CALCULATE ( MAX ( Table1[Date] ), Table1[ID] = "A", Table1[Area] = 3 )
        - CALCULATE ( MIN ( Table1[Date] ), Table1[ID] = "A", Table1[Area] = 1 )
VAR Cat_B =
    CALCULATE ( MAX ( Table1[Date] ), Table1[ID] = "B", Table1[Area] = 3 )
        - CALCULATE ( MIN ( Table1[Date] ), Table1[ID] = "B", Table1[Area] = 1 )
RETURN
    ( Cat_A + Cat_B )
        / 2

Regards
Zubair

Please try my custom visuals

@Liwi

 

aveargetime.png


Regards
Zubair

Please try my custom visuals

Hi There,

Thank you for your suggestion.

 

However I have 1000's of IDs which are constantly added to the data model.

 

I was able to come up with below for same area:

 

VAR Tbl1 =
SUMMARIZE(filter(TableName,[Area]="3"),Append1[ID],"DIFF_FOR_AREA3",DATEDIFF(MIN([DATE]),MAX(DATE]),hour)/24)
RETURN
AVERAGEX ( Tbl1, [DIFF_FOR_AREA3] )

 

Still having issue with difference between 2 areas 😞

 

 

 

 

 

Product Within One Area = 
VAR myTable = SUMMARIZE(Areas,[ID],[Area],"Max",MAX(Areas[Date])-MIN(Areas[Date]))
RETURN AVERAGEX(myTable,[Max])

@Liwi


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thank you Greg.

 

Your solution is very simillar to what I managed to produce:

 

VAR Tbl1 =
SUMMARIZE(filter(TableName,[Area]="3"),Append1[ID],"DIFF_FOR_AREA3",DATEDIFF(MIN([DATE]),MAX(DATE]),hour)/24)
RETURN
AVERAGEX ( Tbl1, [DIFF_FOR_AREA3] )

 

 

However I think your avg takes into account other areas where the result is 0. Like below your average would be 1 while should be 2

 

IDAreaDateResult
A101/01/20180
A305/01/20181
B105/01/20180
B308/01/20183

 

Do you have an idea how can I custommize my below to work for 2 areas? 

 

VAR Tbl1 =
SUMMARIZE(filter(TableName,[Area]="3"),Append1[ID],"DIFF_FOR_AREA3",DATEDIFF(MIN([DATE]),MAX(DATE]),hour)/24)
RETURN
AVERAGEX ( Tbl1, [DIFF_FOR_AREA3] )

 

Thank you for your time 

 

Liwi
Frequent Visitor

I think I figured it ou.

 

Below seems to work in between 2 Areas

 

VAR Tbl2 =
SUMMARIZE(filter(TableName,[Area]="Area 1"||[Area]="Area 3" ),[ID],"AREA_1-AREA_3",DATEDIFF(Min([DATE]),MAX([DATE]),HOUR)/24)
RETURN
AVERAGEX ( Tbl2, [AREA_1-AREA_3] )

 

Thanks a million for your efforts 

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.