Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
walkra
Helper III
Helper III

How to add the result of one month of a measure in the next month?

Hi, how are you.

 

In one measure the value of each month is accumulated. I am wanting to have the sum of that accumulated from the last 6 months (in each month), in a Visualizations Table of a Report.

 

The measure is: 

 

MovimientoEnAlmacen = (CALCULATE(SUM(TMSEGX[ImporteML]); DATESINPERIOD(TablaDeFechas[Date];lastdate(TablaDeFechas[Date]);-100;YEAR); TMSEGX[DebeHaber]="S"))-
(CALCULATE(SUM(TMSEGX[ImporteML]); DATESINPERIOD(TablaDeFechas[Date];lastdate(TablaDeFechas[Date]);-100;YEAR); TMSEGX[DebeHaber]="H"))
 
For Example, (in the Report): 
 
Año          Mes          MovimientoEnAlmacen        Suma (??)
 
2017         enero       10000                                    10000
2017         febrero     12000                                    22000
2017         marzo       15000                                    37000
2017         abril          10000                                    47000
2017         mayo         500                                       47500
2017         junio          500                                       48000
2017         julio           100                                       38100
2017         agosto       5000                                     31100
 
As in each month the total of the rest of the months is added up, I do not know how to add that total amount (of each month) of the last six months.
 
If you can help me, I would be very grateful. Thank you, very much. 
(I'm sorry my English). 
 
1 ACCEPTED SOLUTION

Hi @walkra,

I have tested your pbix file and I think the problem may due to the row context with your data, you could try to swith off the

hierarchy:

1.PNG

And try to modify the Measure B as below:

Measure B = SUMX(FILTER(ALLSELECTED('Calendario'[Año - MESNumb]),'Calendario'[Año - MESNumb]<=MAX('Calendario'[Año - MESNumb])),[MovimientoEnAlmacen2])

Result:

1.PNG

You could also download the pbix file to have a view.

 

Regards,

Daniel He

 

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

8 REPLIES 8
walkra
Helper III
Helper III

To clarify (I forgot the MonthMove column): 

 

Año          Mes          MonthMove               MovimientoEnAlmacen        Suma (??)
 
2017         enero            0                                 10000                                   10000
2017         febrero         2000                            12000                                  22000
2017         marzo           3000                            15000                                  37000
2017         abril             -5000                            10000                                  47000
2017         mayo           -9500                               500                                   47500
2017         junio               0                                   500                                   48000
2017         julio             -400                                100                                    38100
2017         agosto         4900                              5000                                   31100

Hi @walkra,

Based on my test, you need to add an index column for your data view in query editor:

https://stackoverflow.com/questions/45715963/creating-an-index-column-for-power-bi

And try below measure:

Measure 2 = SUMX(FILTER(ALL('yourtable'),'yourtable'[Index]<=MAX('yourtable'[Index])),'yourtable'[MovimientoEnAlmacen])

Result:

1.PNG

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi, Daniel. Thank you very much for your answer.

 

Unfortunately I must be doing something wrong because it did not work.

 

I did a test with a smaller table:

CentroAlmacenAñoMesFechaDocumentoTotalMovimientosIndex
A010A0101/1/201750001
A010A01010/1/201740002
A010A01020/1/201710003
A010A0101/2/201710004
A010A01028/2/201710005
A010A01030/3/201730006
A010A0101/4/2017-15007
A010A01010/4/2017-15008
A010A01011/4/2017-20009
A010A01015/5/2017-450010
A010A01016/5/2017100011
A010A01018/5/2017-50012
A010A01019/5/2017-100013
A010A01030/5/2017-450014
A010A0101/6/2017015
A010A0101/7/2017-40016
A010A0101/8/2017490017

 

I used a smaller measure of the "MovimientoEnAlmacen" but with similar characteristics:

 

MovimientoEnAlmacen2 = CALCULATE(SUM(TablaSumaPrueba[TotalMovimientos]); DATESINPERIOD(Calendario[Date];lastdate(Calendario[Date]);-100;YEAR))

 

And your measure: 

 

Measure B = SUMX(FILTER(ALL('TablaSumaPrueba');'TablaSumaPrueba'[Index]<=MAX('TablaSumaPrueba'[Index]));'TablaSumaPrueba'[MovimientoEnAlmacen2])

 

But the result is in both columns the same result: 

 

Reporte AB.png

Here the report: 

Reporte AC.png

The result in "Measure B" in the reporte isn´t the same that in the column "Measure 2" of your report. 

What can be wrong?

 

Again, Thank you, very much

 

 

Hi @walkra,

Due to I could not reproduce your problem, could you please share your pbix file to have a test if possible? You could upload your report to your OneDrive or Dropbox and send the link here.

 

Regards,

Daniel He 

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi, Daniel, How are you? I hope that you are fine. 

Here you have the link:

 

https://1drv.ms/f/s!At33Gf20rWIrelarDHcl9ULspvA

 

In the Publico folder upload "acumulado.pbix" and two excels file (in case you need them: Calendar and the main table). 

 

(I was thinking if the problem is not due to some configuration that I have in my Power BI or in my pc?).

 

Thank you, very much. 

Hi @walkra,

I have tested your pbix file and I think the problem may due to the row context with your data, you could try to swith off the

hierarchy:

1.PNG

And try to modify the Measure B as below:

Measure B = SUMX(FILTER(ALLSELECTED('Calendario'[Año - MESNumb]),'Calendario'[Año - MESNumb]<=MAX('Calendario'[Año - MESNumb])),[MovimientoEnAlmacen2])

Result:

1.PNG

You could also download the pbix file to have a view.

 

Regards,

Daniel He

 

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Excelente!!!

Thank You Very Much. 

Hi, Daniel, How are you?. I hope that you are fine.

 

Sorry for the inconvenience again, but there was a problem. The logic that I indicated is correct but has a problem: if it is filtered, for example, four consecutive months, the cumulative calculation is of those four months that were chosen. How could it be programmed so that when it filters, it continues to accumulate from the first day, it still leaks for a few months? Please, tell me if I open another ticket (but, please, if you can help me).

 

Thank You!!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.