Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Maximum Value from table

Hi everyone, 

Im having difficulty displaying my maximum value from a table, i would appreciate if anyone could help me.

The error shows that " Argument "6" in function SWITCH is required"

My code:

Max =
VAR ValueDisplayed=
CALCULATETABLE(
ADDCOLUMNS(
    SUMMARIZE ('energykwh energydata','energykwh energydata'[DATE],'energykwh energydata'[Time],'energykwh energydata'[energydata_value]),
    "@abc",[energydata_value]
),
ALLSELECTED()
)
VAR MinVal = MINX(ValueDisplayed, [@ABC])
VAR MaxVal=MAXX(ValueDisplayed, [@abc])
VAR CurrentVaL= [energydata_value]
VAR Result=
    SWITCH(
        TRUE(),
        CurrentVal= MinVal, 1,
CurrentVaL= MaxVal,2,)

RETURN
    Result

 

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Anonymous ,

     

    Please note that your code has an extra comma at the underscore I marked:

     

     

    If you just want to apply a flag for the max and min value, you could simply use:

    Column = 
    var _max=MAX('energykwh energydata'[energydata_value])
    var _min=MIN('energykwh energydata'[energydata_value])
    return SWITCH(TRUE(), [energydata_value]=_max,2,[energydata_value]=_min,1)

     

    Best Regards,
    Eyelyn Qin
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

4 Replies

  • smpa01's avatar
    smpa01
    Community Champion

    Anonymous  get rid of the last comma in SWITCH

     

    VAR Result=
        SWITCH(
            TRUE(),
            CurrentValMinVal1,
    CurrentVaLMaxVal,2)

     

    RETURN
        Result
    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi, i still am unabe to extract the maximum value out from the table. Do you by any chance know how to extract the value? My code was not working. This is my table.

       

      • smpa01's avatar
        smpa01
        Community Champion

        Anonymous  can you please provide some sample dat and expected output?

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    Please note that your code has an extra comma at the underscore I marked:

     

     

    If you just want to apply a flag for the max and min value, you could simply use:

    Column = 
    var _max=MAX('energykwh energydata'[energydata_value])
    var _min=MIN('energykwh energydata'[energydata_value])
    return SWITCH(TRUE(), [energydata_value]=_max,2,[energydata_value]=_min,1)

     

    Best Regards,
    Eyelyn Qin
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.