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.
suppose I have the following table
id | group | val1 |
1 | A | 2 |
2 | A | 3 |
3 | A | 4 |
4 | B | 4 |
5 | B | 6 |
6 | B | 2 |
How would I get the following result?
id | group | val1 | diff |
1 | A | 2 | 0 |
2 | A | 3 | 1 |
3 | A | 4 | 1 |
4 | B | 4 | 0 |
5 | B | 6 | 2 |
6 | B | 2 | -4 |
Explanation of new column diff:
1. It is the difference between the current row and previous row of column val1
2. Whenever a new group starts in Group column the difference resets to 0
Essestially, the problem is how to subtract current value from it's previous value in a column by group (based on some third column)?
Solved! Go to Solution.
@Anonymous , Try a new column like
new column =
var _max = maxx(filter(table, [group] = earlier([group]) && [ID] < earlier([ID])),[ID])
return
val1 - maxx(filter(table, [group] = earlier([group]) && [ID] = _max),[val1])
@Anonymous , Try a new column like
new column =
var _max = maxx(filter(table, [group] = earlier([group]) && [ID] < earlier([ID])),[ID])
return
val1 - maxx(filter(table, [group] = earlier([group]) && [ID] = _max),[val1])
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 |
---|---|
108 | |
105 | |
87 | |
74 | |
66 |
User | Count |
---|---|
124 | |
112 | |
96 | |
82 | |
72 |