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.
I am stuck trying to create either a calculated column or a measure that will give me an array of values calculated from two columns in a table. The first column contains the groups in which the values fall (Group), and the second contains the values (Value). What I want to do is to calculate the mode of the values per group and then, per row, subtract the value from that mode.
Here is an example of how the calculations would look (the column Mode/Group isn't necessary and can be a variable)
'Data table'
Group | Value | Mode/group | Calculated Value |
1 | 7 | 4 | 3 |
2 | 2 | 2 | 0 |
3 | 6 | 6 | 0 |
1 | 4 | 4 | 0 |
2 | 4 | 2 | 2 |
1 | 4 | 4 | 0 |
3 | 6 | 6 | 0 |
2 | 2 | 2 | 0 |
I want to be able to later show the maximum, minimum, and average value of this difference per group, and also to be able to filter it for other columns in this table. Therefore I'm not sure if a calculated column or a measure would be better.
Thanks for any help.
Solved! Go to Solution.
Try this for your calculated column
New column =
VAR mode_ =
MINX (
TOPN (
1,
CALCULATETABLE (
ADDCOLUMNS (
DISTINCT ( Table1[Value] ),
"Frequency", CALCULATE ( COUNT ( Table1[Value] ) )
),
ALLEXCEPT ( Table1, Table1[Group] )
),
[Frequency], 0
),
Table1[Value]
)
RETURN
Table1[Value] - mode_
and check this out for the MODE pattern
https://www.daxpatterns.com/statistical-patterns/#
|
Please accept the solution when done and consider giving a thumbs up if posts are helpful. Contact me privately for support with any larger-scale BI needs, tutoring, etc. Cheers |
Thanks, that did the trick.
Try this for your calculated column
New column =
VAR mode_ =
MINX (
TOPN (
1,
CALCULATETABLE (
ADDCOLUMNS (
DISTINCT ( Table1[Value] ),
"Frequency", CALCULATE ( COUNT ( Table1[Value] ) )
),
ALLEXCEPT ( Table1, Table1[Group] )
),
[Frequency], 0
),
Table1[Value]
)
RETURN
Table1[Value] - mode_
and check this out for the MODE pattern
https://www.daxpatterns.com/statistical-patterns/#
|
Please accept the solution when done and consider giving a thumbs up if posts are helpful. Contact me privately for support with any larger-scale BI needs, tutoring, etc. Cheers |
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 |
---|---|
47 | |
24 | |
20 | |
15 | |
12 |
User | Count |
---|---|
55 | |
48 | |
43 | |
19 | |
18 |