Forum Discussion
charcoal
2 years agoRegular Visitor
Retrieving value from earlier row with multiple filters
Major novice here, trying to retrieve usage values from a previous date of the same Product/Color/Machine to use to calculate change from previous day. Trying to highlight any major change from previ...
- 2 years ago
Please try this:
Last Val = VAR LastStartTime = CALCULATE ( MAX ( 'Table'[Start Time] ), FILTER ( ALLEXCEPT ( 'Table', 'Table'[Product], 'Table'[Color], 'Table'[Machine] ), 'Table'[Start Time] < EARLIER ( 'Table'[Start Time] ) ) ) RETURN CALCULATE ( MAX ( 'Table'[Usage] ), FILTER ( ALLEXCEPT ( 'Table', 'Table'[Product], 'Table'[Color], 'Table'[Machine] ), 'Table'[Start Time] = LastStartTime ) )
danextian
Super User
2 years agoHi charcoal
Try this:
Last Val =
CALCULATE (
MAX ( 'Table'[Usage] ),
FILTER (
ALLEXCEPT ( 'Table', 'Table'[Product], 'Table'[Color], 'Table'[Machine] ),
'Table'[Start Time] < EARLIER ( 'Table'[Start Time] )
)
)
- charcoal2 years agoRegular Visitor
Thanks danextian
However it looks like the result is still out of sync with the previous rows for that combo, showing the same value over and over again.
One thing to note, the sample set shown here only shows one product/color combo, but the full data set is an array of many Product #'s and Color #'s. Larger example set including multiple products and colors below:
Start Time Product Color Machine Usage 6/4/2024 387 187 B1 126 6/4/2024 387 187 B2 137 6/4/2024 387 187 B3 138 6/4/2024 387 187 B4 93 6/4/2024 387 194 B1 144 6/4/2024 387 194 B2 130 6/4/2024 387 194 B3 130 6/4/2024 387 194 B4 79 6/3/2024 220 187 B1 105 6/3/2024 220 187 B2 61 6/3/2024 220 187 B3 84 6/3/2024 220 187 B4 114 6/3/2024 387 194 B1 146 6/3/2024 387 194 B2 131 6/3/2024 387 194 B3 131 6/3/2024 387 194 B4 78 5/31/2024 220 194 B1 142 5/31/2024 220 194 B2 42 5/31/2024 220 194 B3 50 5/31/2024 220 194 B4 120 5/22/2024 387 187 B1 126 5/22/2024 387 187 B2 138 5/22/2024 387 187 B3 137 5/22/2024 387 187 B4 94 5/21/2024 387 187 B1 125 5/21/2024 387 187 B2 138 5/21/2024 387 187 B3 137 5/21/2024 387 187 B4 94 5/21/2024 387 194 B1 145 5/21/2024 387 194 B2 131 5/21/2024 387 194 B3 130 5/21/2024 387 194 B4 80 5/20/2024 387 187 B1 125 5/20/2024 387 187 B2 139 5/20/2024 387 187 B3 136 5/20/2024 387 187 B4 93 5/14/2024 220 187 B1 108 5/14/2024 220 187 B2 83 5/14/2024 220 187 B3 85 5/14/2024 220 187 B4 113 5/13/2024 387 187 B1 128 5/13/2024 387 187 B2 138 5/13/2024 387 187 B3 137 5/13/2024 387 187 B4 94 5/10/2024 220 187 B1 107 5/10/2024 220 187 B2 74 5/10/2024 220 187 B3 85 5/10/2024 220 187 B4 111 5/10/2024 220 194 B1 147 5/10/2024 220 194 B2 54 5/10/2024 220 194 B3 61 5/10/2024 220 194 B4 125 5/6/2024 387 187 B1 127 5/6/2024 387 187 B2 138 5/6/2024 387 187 B3 137 5/6/2024 387 187 B4 93 5/3/2024 387 194 B1 148 5/3/2024 387 194 B2 132 5/3/2024 387 194 B3 131 5/3/2024 387 194 B4 79 5/1/2024 220 187 B1 107 5/1/2024 220 187 B2 85 5/1/2024 220 187 B3 88 5/1/2024 220 187 B4 113 4/30/2024 220 187 B1 107 4/30/2024 220 187 B2 73 4/30/2024 220 187 B3 85 4/30/2024 220 187 B4 113 4/24/2024 387 187 B1 128 4/24/2024 387 187 B2 138 4/24/2024 387 187 B3 137 4/24/2024 387 187 B4 94 4/23/2024 387 194 B1 148 4/23/2024 387 194 B2 131 4/23/2024 387 194 B3 131 4/23/2024 387 194 B4 79 4/20/2024 220 194 B1 145 4/20/2024 220 194 B2 56 4/20/2024 220 194 B3 61 4/20/2024 220 194 B4 125 4/16/2024 220 187 B1 106 4/16/2024 220 187 B2 76 4/16/2024 220 187 B3 83 4/16/2024 220 187 B4 111 4/15/2024 387 187 B1 128 4/15/2024 387 187 B2 137 4/15/2024 387 187 B3 137 4/15/2024 387 187 B4 94 4/15/2024 387 194 B1 148 4/15/2024 387 194 B2 132 4/15/2024 387 194 B3 130 4/15/2024 387 194 B4 79 4/13/2024 220 187 B1 106 4/13/2024 220 187 B2 78 4/13/2024 220 187 B3 84 4/13/2024 220 187 B4 112 4/11/2024 387 187 B1 127 4/11/2024 387 187 B2 138 4/11/2024 387 187 B3 138 4/11/2024 387 187 B4 94 4/8/2024 387 187 B1 127 4/8/2024 387 187 B2 137 4/8/2024 387 187 B3 137 4/8/2024 387 187 B4 93 4/4/2024 387 194 B1 147 4/4/2024 387 194 B2 132 4/4/2024 387 194 B3 131 4/4/2024 387 194 B4 78 4/3/2024 387 194 B1 145 4/3/2024 387 194 B2 130 4/3/2024 387 194 B3 130 4/3/2024 387 194 B4 79 4/2/2024 387 187 B1 126 4/2/2024 387 187 B2 139 4/2/2024 387 187 B3 138 4/2/2024 387 187 B4 93 4/2/2024 387 194 B1 148 4/2/2024 387 194 B2 132 4/2/2024 387 194 B3 131 4/2/2024 387 194 B4 79 4/1/2024 387 187 B1 129 4/1/2024 387 187 B2 139 4/1/2024 387 187 B3 137 4/1/2024 387 187 B4 95 - danextian2 years ago
Super User
Please try this:
Last Val = VAR LastStartTime = CALCULATE ( MAX ( 'Table'[Start Time] ), FILTER ( ALLEXCEPT ( 'Table', 'Table'[Product], 'Table'[Color], 'Table'[Machine] ), 'Table'[Start Time] < EARLIER ( 'Table'[Start Time] ) ) ) RETURN CALCULATE ( MAX ( 'Table'[Usage] ), FILTER ( ALLEXCEPT ( 'Table', 'Table'[Product], 'Table'[Color], 'Table'[Machine] ), 'Table'[Start Time] = LastStartTime ) )- charcoal2 years agoRegular Visitor
It looks like this worked perfectly, thank you. Definitely to expand my knowledge and use of variables.
Is there a simple way to calculate the rolling average from the previous 3 entries using this same general format?