Forum Discussion
Aggregate quantities by category
Hi all,
I am having troubles with a simple topic. I have a table with several columns, one of them is the number of weeks of delay, another one is the quantity and another one is the year. I use table to show information aggregating info per category and year. Image below:
As you can see it is simple, P BI carries out all the aggregation, summarizing each of the categories in rows with quantities for each year.
The problem comes when I try to calcular aggregated values in cumulative way. I use the following measure:
4 Replies
- FowmySuper User
japlazaheras
Not sure how your model is built but, can you try the following measure?Agg3 = VAR currentIdx = SELECTEDVALUE(tentregapedidos[Salida-Confirmado]) return CALCULATE( SUM(tentregapedidos[Qty]), tentregapedidos[Salida-Confirmado] <= currentIdx, REMOVEFILTERS( tentregapedidos[Salida-Confirmado]) )- japlazaherasRegular Visitor
Hello,
It almost worked. If I just make a table and I select in a filter outside the Year then it aggregates well. See picture below:
However, the goal is to compare Years and Quarters so instead of a Table I am trying to have a matrix where columns are Years and the Quarter is selected in a filter (slicer) in the page. Adding this format, and selecting 2 years (if I select matrix but only one year it works the same than the picture above) the result is as follows:
As you can see there are several bad effects, one is that blank / cero rows the context Year doesn't work so, for example, 2020 4 wks you get the 2021 0 weeks. Why 2021 0 weeks? It looks like the measure , if there is no values resets and takes the initial value not the previous one. One minor change on your proposal helps:
Agg3 =VAR currentIdx = SELECTEDVALUE(tentregapedidos[Salida-Confirmado])returnCALCULATE(SUM(tentregapedidos[Qty]),tentregapedidos[Salida-Confirmado] <= currentIdx,ALLSELECTED( tentregapedidos[Salida-Confirmado]))If I do not REMOVEFILTERS then the result is:If solves the context problem of the Year but if there is one row in a year with cero then the value is reset to the initial one, first row of the year.
- FowmySuper User
japlazaheras
I will be able to find out the issue by looking at the model in your file, kindly share a sample PBIX file with the same structure and remove confidential data if any.
You can save in a cloud drive like Google Drive or One Drive then share the link here.