March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Good afternoon
I have a table with 4 columns. ColA ColB ColC and ColD. they contain numerical values.
If I do a sum or an average of the values in each column, I get a number for each. I need to make a decision based on which column contains the lowest sum or average value. How do I get a return that states which column returns the lowest value.
If the returned value is "ColA", Then that allows me to present information on another card. How would I begin to do this?
I appreciate any direction or help in this area.
Lola
Solved! Go to Solution.
Hi @MyWeeLola
Please try
Lowest Sum =
MAXX (
TOPN (
1,
ADDCOLUMNS (
{ "ColA", "ColB", "ColC", "ColD" },
"@Sum",
SWITCH (
[Value],
"ColA", SUM ( TableName[ColA] ),
"ColB", SUM ( TableName[ColB] ),
"ColC", SUM ( TableName[ColC] ),
"ColD", SUM ( TableName[ColD] )
)
),
[@Sum], ASC
),
[Value]
)
Hi @MyWeeLola
Please try
Lowest Sum =
MAXX (
TOPN (
1,
ADDCOLUMNS (
{ "ColA", "ColB", "ColC", "ColD" },
"@Sum",
SWITCH (
[Value],
"ColA", SUM ( TableName[ColA] ),
"ColB", SUM ( TableName[ColB] ),
"ColC", SUM ( TableName[ColC] ),
"ColD", SUM ( TableName[ColD] )
)
),
[@Sum], ASC
),
[Value]
)
@tamerj1 Thank you for the response. Am I correct in assuming that if I change the MAXX to MINX, I will get the lowest value?
Lola
@MyWeeLola
Acually no you will get the same value in both cases. The reason is TOPN returns only one record (assumining no ties) therefore it does not matter whether you use MINX or MAXX. IF you want the max value you need to delete ASC from inside TOPN.
However, it is also good idea to concatenate the results in case of ties such as:
Lowest Sum =
CONCATENATEX (
TOPN (
1,
ADDCOLUMNS (
{ "ColA", "ColB", "ColC", "ColD" },
"@Sum",
SWITCH (
[Value],
"ColA", SUM ( TableName[ColA] ),
"ColB", SUM ( TableName[ColB] ),
"ColC", SUM ( TableName[ColC] ),
"ColD", SUM ( TableName[ColD] )
)
),
[@Sum], ASC
),
[Value],
UNICHAR ( 10 ),
[Value], ASC
)
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
19 | |
19 | |
16 | |
8 | |
5 |
User | Count |
---|---|
36 | |
28 | |
16 | |
16 | |
12 |