Forum Discussion

jas_power's avatar
jas_power
Helper I
3 years ago
Solved

Cumulative Calculation Multiplying Values from Previous Row

Hello,     I need to create a cumulative measure that references the previous rows values like this: Where refPeriod comes from the dim table Periods, allItemsByItem comes from the fact table...
  • v-yueyunzh-msft's avatar
    3 years ago

    Hi, jas_power 

    According to your description, you want to calculate the " cumulative measure that references the previous rows".

    For your need , in your image you have many tables and make relationships between tables.

    I don't have your raw data, and I can't simulate your corresponding inter-table relationships in my tests, but we use your sample data to simulate the logic of calculating this situation, and you can try to find the corresponding values in your inter-table relationships, and then replace the variables to achieve your needs, this is my test data:

    We can create a measure like this:

    Measure = var _min_date = MINX(ALLSELECTED('Table'),[refPeriod])
    var _value =MAXX( FILTER( ALLSELECTED('Table'),'Table'[refPeriod] =_min_date) , [value])
    var _date = MAX('Table'[refPeriod])
    var _alltem =SELECTCOLUMNS( FILTER(ALLSELECTED('Table') , 'Table'[refPeriod] < _date) ,"alltem" , [alltemsbyItem])
    return
    IF(_value* PRODUCTX(_alltem,[alltem])=BLANK(),_value,_value* PRODUCTX(_alltem,[alltem]))

    Then we put this measure in the visual and we will meet your need , the result is as follows:

    If this can not helo you meet your need , can you share the .pbix file without sensitive data to us so that we can help you better!

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    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