Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Handle Cumulative sums coming from database

How to handle cumulative sums coming from DB at key column(Prod ID) level, But i want to aggregate at Product dimension ( Category, name) in power bi .

  • Hi Anonymous 

     

    The [month] you need to change it type to date will contribute to calculation.

    Then create a new table named 'output in power bi' via the following expression:

    output in power bi =
    SUMMARIZE(
        'input from DB',
        'input from DB'[country],
        'input from DB'[month],
        "cnt", SUM( 'input from DB'[count] )
    )
    

    And add new column in the 'output in power bi'

    3mnth running total =
    SUMX(
        FILTER(
            'output in power bi',
            [month] >= DATEADD( 'output in power bi'[month], -3, MONTH )
                && [month] <= EARLIER( 'output in power bi'[month] )
                && [country] = EARLIER( 'output in power bi'[country] )
        ),
        [cnt]
    )
    

    the result:

     

    I put the pbix file in the attachment you can refer.

     

    Best Regards

    Community Support Team _ chenwu zhu

     

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

3 Replies

  • Anonymous , Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

     

    I think we should create a new column that is not cumulative and use that

     

    new column =

    var _max = maxx(filter(Table, [Product] < earlier([Product]))  ,[Product])

    // or use this on value var _max = maxx(filter(Table, [value] < earlier([value])) ,[Product]) 

    return

    [Value] - maxx(filter(Table, [Product] =_max) ,[Product]) 

  • Anonymous's avatar
    Anonymous
    Not applicable

    input from DB:

    monthcountryProduct_Idcount3mnth Running total
    202011AP11010
    202012AP12030
    202011AP23030
    202012AP21242
    202101AP22062
    202011BP21515
    202012BP21025
    202101BP2328

    output in power bi:

    country_descmnthcnt3mnth running total
    A_desc2020114040
    A_desc2020124282
    A_desc20210120102

     

    Note: our assumption is to create cumulative sums in DB to improve performace of power bi by reducing number of measures.  

    • v-chenwuz-msft's avatar
      v-chenwuz-msft
      Community Support

      Hi Anonymous 

       

      The [month] you need to change it type to date will contribute to calculation.

      Then create a new table named 'output in power bi' via the following expression:

      output in power bi =
      SUMMARIZE(
          'input from DB',
          'input from DB'[country],
          'input from DB'[month],
          "cnt", SUM( 'input from DB'[count] )
      )
      

      And add new column in the 'output in power bi'

      3mnth running total =
      SUMX(
          FILTER(
              'output in power bi',
              [month] >= DATEADD( 'output in power bi'[month], -3, MONTH )
                  && [month] <= EARLIER( 'output in power bi'[month] )
                  && [country] = EARLIER( 'output in power bi'[country] )
          ),
          [cnt]
      )
      

      the result:

       

      I put the pbix file in the attachment you can refer.

       

      Best Regards

      Community Support Team _ chenwu zhu

       

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