Forum Discussion

kurt_peters's avatar
kurt_peters
New Member
3 years ago
Solved

Sum values between two values

Hello Everyone, I'm trying to sum values between two values, for exemple:   This is a sample of my data. I would like to pull a bar chart that: - between 0 and 3 sums values of [qnt] of ...
  • v-yueyunzh-msft's avatar
    3 years ago

    Hi, kurt_peters 

    Here are the steps you can follow:

    (1)This is my test data:

    (2)We can click "New Table" and enter:

    Table 2 = 
    var _min=MIN('Table'[min])
    var _max=MAX('Table'[max])
    var _table=GENERATESERIES(_min,_max,1)
    var _crossjoin=CROSSJOIN('Table',_table)
    var _output=FILTER(_crossjoin,[Value]<=[max]&&[Value]>=[min])
    return
    _output
    

    (3)We can create a 'Status' table by "Enter Data":

    (4)Then we can create a calculated column in 'Status' Table:

    Sum = 
    SWITCH([Status],
    "0-2" ,   var _t =SUMX( FILTER('Table','Table'[Idx] in   DISTINCT(SELECTCOLUMNS( FILTER('Table 2', 'Table 2'[Value] in {0,1,2}),"Id",[Idx])) ) ,[qnt]) return _t      ,
    "3-4", var _t =SUMX( FILTER('Table','Table'[Idx] in   DISTINCT(SELECTCOLUMNS( FILTER('Table 2', 'Table 2'[Value] in {3,4}),"Id",[Idx])) ) ,[qnt]) return _t            ,
    "5-6",   var _t =SUMX( FILTER('Table','Table'[Idx] in   DISTINCT(SELECTCOLUMNS( FILTER('Table 2', 'Table 2'[Value] in {5,6}),"Id",[Idx])) ) ,[qnt]) return _t           ,
    var _t =SUMX( FILTER('Table','Table'[Idx] in   DISTINCT(SELECTCOLUMNS( FILTER('Table 2', 'Table 2'[Value] in {6,7}),"Id",[Idx])) ) ,[qnt]) return _t 
        )

    (5)Then we can meet your need, the result is as follows, we can put the fileds in the visual:

    If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

     

    Best Regards,

    Aniya Zhang

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