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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
MattiaMaetini
Helper I
Helper I

DAX total running on a temp aggregate var table issue

Hi all,

My goal it's to obtain a running total from my ranked aggregate var table.

 

This could be a set of valid data input (FORNITORI_F into the dax code below):

ID FornitoreFK_ID Fornitore AggregatoImporto
510100
610200
13150
221000
422000
823000

 

As a first temp output I'm able to obtain this var table:

 

DEFINE

VAR SommaImporti =
ADDCOLUMNS(
SUMMARIZE(
FILTER(FORNITORI_F, FORNITORI_F[Anno] = 2024 && FORNITORI_F[FK_ID_CALENDARIO]=1004),
FORNITORI_F[FK_ID_ANAGFORNITOREAGGREGATO],
"ImportoTotale", SUM(FORNITORI_F[ImportoPosizioneIVAInclusa])
),
"Range", RANKX(
SUMMARIZE(
FILTER(FORNITORI_F, FORNITORI_F[Anno] = 2024 && FORNITORI_F[FK_ID_CALENDARIO]=1004),
FORNITORI_F[FK_ID_ANAGFORNITOREAGGREGATO],
"ImportoTotale", SUM(FORNITORI_F[ImportoPosizioneIVAInclusa])
),
[ImportoTotale], , DESC
)
)

 

 

FK_ID AnagFornitoreAggregato (group by)Importo (sum)Ranking
260001
103002
31503

 

Var SommaTotale will be 6450:

VAR SommaTotale = SUMX(SommaImporti, [ImportoTotale])

 

 

Now I need to creata a running total like this:

FK_ID AnagFornitoreAggregatoImportoRankingRUNNING TOTAL
2600016000
1030026300
315036450

But what I have is:

 

FK_ID AnagFornitoreAggregatoImportoRankingRUNNING TOTAL
2600016450
1030026450
315036450

 

VAR TabellaOrdinata =
ADDCOLUMNS(
SommaImporti,
"SommaCumulata", CALCULATE(SUMX(SommaImporti, [ImportoTotale]),

FILTER(SommaImporti, [Range] < MAXX(SommaImporti, [Range])))
)

 

I'm not able to iterate over my temp table SommaImporti.

 

Could you help me to solve it?

Tks in advance,

BR,

M

 

1 ACCEPTED SOLUTION

Hi @rajendraongole1 ,

Unfortunately code doesn't work: please find dax studio screenshot on the bottom.

 

It seems try to filter a column from a VAR table create some problem.

 

Any other suggest in order to solve it?

BR,
M

 

MattiaMaetini_0-1730186794795.png

 

View solution in original post

2 REPLIES 2
rajendraongole1
Super User
Super User

Hi @MattiaMaetini - In your TabellaOrdinata variable, calculate the cumulative total by filtering SommaImporti to include only those rows where the rank is less than or equal to the current row's rank.

Updated formula FYR:

DEFINE
VAR SommaImporti =
ADDCOLUMNS(
SUMMARIZE(
FILTER(FORNITORI_F, FORNITORI_F[Anno] = 2024 && FORNITORI_F[FK_ID_CALENDARIO] = 1004),
FORNITORI_F[FK_ID_ANAGFORNITOREAGGREGATO],
"ImportoTotale", SUM(FORNITORI_F[ImportoPosizioneIVAInclusa])
),
"Range", RANKX(
SUMMARIZE(
FILTER(FORNITORI_F, FORNITORI_F[Anno] = 2024 && FORNITORI_F[FK_ID_CALENDARIO] = 1004),
FORNITORI_F[FK_ID_ANAGFORNITOREAGGREGATO],
"ImportoTotale", SUM(FORNITORI_F[ImportoPosizioneIVAInclusa])
),
[ImportoTotale], , DESC
)
)

VAR SommaTotale = SUMX(SommaImporti, [ImportoTotale])

VAR TabellaOrdinata =
ADDCOLUMNS(
SommaImporti,
"SommaCumulata",
CALCULATE(
SUMX(
FILTER(SommaImporti, [Range] <= EARLIER([Range])),
[ImportoTotale]
)
)
)

RETURN
TabellaOrdinata

 

changes , The EARLIER function allows us to reference the current row’s rank (Range) within the filter of SommaImporti, so that the filter accumulates totals up to the current rank.

Hope it works. 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Hi @rajendraongole1 ,

Unfortunately code doesn't work: please find dax studio screenshot on the bottom.

 

It seems try to filter a column from a VAR table create some problem.

 

Any other suggest in order to solve it?

BR,
M

 

MattiaMaetini_0-1730186794795.png

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.