Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be 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

Reply
MyWeeLola
Helper II
Helper II

Finding a column with the lowest average value

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

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

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]
)

View solution in original post

4 REPLIES 4
MyWeeLola
Helper II
Helper II

@tamerj1 thank you for the responses. All is working as it should, thank you.

tamerj1
Super User
Super User

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
)

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.