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.
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
ID | Area | Date |
A | 1 | 01/01/2018 |
A | 2 | 02/01/2018 |
A | 3 | 05/01/2018 |
A | 3 | 06/01/2018 |
B | 1 | 05/01/2018 |
B | 2 | 06/01/2018 |
B | 3 | 08/01/2018 |
B | 3 | 10/01/2018 |
B | 3 | 11/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
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])
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
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])
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
ID | Area | Date | Result |
A | 1 | 01/01/2018 | 0 |
A | 3 | 05/01/2018 | 1 |
B | 1 | 05/01/2018 | 0 |
B | 3 | 08/01/2018 | 3 |
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
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
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
106 | |
98 | |
78 | |
64 | |
58 |
User | Count |
---|---|
148 | |
113 | |
97 | |
84 | |
67 |