Forum Discussion

itchyeyeballs's avatar
itchyeyeballs
Impactful Individual
9 years ago
Solved

Previous Total

Hi all,   I'm trying to calculate a figure based on a previous total, I need to decrement two columns in order to calculate but having a few issues.   My data and required output looks like   ...
  • itchyeyeballs's avatar
    itchyeyeballs
    9 years ago

    Hi tringuyenminh92

     

    Thank you for the help, I wasn't able to follow your complete solution but used some of the core parts to resolve.

     

    As you suggested I merged the two columns I wanted to filter on into a single column, I did this in the initial query

     

    = Table.AddColumn(#"Renamed Columns", "Year_level", each [Year_]*100+[level])

     

    I then created a function to dynamically work out the value (this included an extra filter in the calculate)

    =VAR
    	yearx = max(table[level])
    RETURN
    	Calculate(
    		sum(table[value]),
    		filter(all(table[level],table[Year]),table[year_level]= yearx-101),
    		table[another_col]="END"
    	)

    I then created another measure to ensure the overall total was calulcated correctly

     

    =if(HASONEVALUE(table[Year]),
    [Measure],
    sumx(values(Table[Year]),[Measure])
    )

    Which seems to work.

     

    Thank you for the help, was invaluable