Forum Discussion
Limit the cumulative sum using DAX
Hello Friends, I am having a problem when creating a sum calculated using DAX and I can not find the solution.
I have the following set of data, where, on the one hand, I have the budget for a certain number of periods and on the other the expenditure that has been executed.
I have been asked to display on a line chart the Accumulated budget and expense, which I have achieved with the following code.
Hi @Syndicate_Admin, thanks for the answer, it is a partial help to the problem I have, but as we see a straight line is still drawn for the current month, 202211.
At the moment I have overcome it in this way:gasto acum = VAR fecha_resta_mes = DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, DAY ( TODAY () ) ) VAR Result = IF( MAX('Table'[periodo])<=CONVERT(FORMAT(fecha_resta_mes,"yyyymm"),INTEGER), CALCULATE( SUM('Table'[gasto]), FILTER( ALLSELECTED('Table'),[periodo]<=MAX('Table'[periodo]) ) ) ) RETURN ResultObtained this result:
I would like to know if anyone has any better solution, since for the moment I would be leaving it at that.
Thank you.
2 Replies
- v-yalanwu-msft
Community Support
Hi, Syndicate_Admin ;
May be could try this measure.
gasto acum = IF(MAX('Table'[periodo])<=CONVERT(FORMAT(TODAY(),"yyyymm"),INTEGER), CALCULATE(SUM('Table'[gasto]),FILTER(ALLSELECTED('Table'),[periodo]<=MAX('Table'[periodo]))))The final show:
Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.- Syndicate_Admin
Administrator
Hi @Syndicate_Admin, thanks for the answer, it is a partial help to the problem I have, but as we see a straight line is still drawn for the current month, 202211.
At the moment I have overcome it in this way:gasto acum = VAR fecha_resta_mes = DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, DAY ( TODAY () ) ) VAR Result = IF( MAX('Table'[periodo])<=CONVERT(FORMAT(fecha_resta_mes,"yyyymm"),INTEGER), CALCULATE( SUM('Table'[gasto]), FILTER( ALLSELECTED('Table'),[periodo]<=MAX('Table'[periodo]) ) ) ) RETURN ResultObtained this result:
I would like to know if anyone has any better solution, since for the moment I would be leaving it at that.
Thank you.