cancel
Showing results for
Did you mean:  Helper II

## Sumx function isn't working for my view

Hi there,

my sumx function isnt working for a total qty measure i calculated.

I have my Qty measure where I am replacing my empty rows with the previous values as such

final Qty =

VAR CurrentValue =
SUM ( data[qty])
VAR PreviousValue =
if(
sum(data[qty]) = BLANK(),
CALCULATE(
sum(data[qty]),
date[date_dt] = MAX(date[date_dt])-1,
))
RETURN
if(
max(date[date_dt]) =max(date[date_dt]) ,
CurrentValue + PreviousValue,
CurrentValue
)

When I put this total on my table view, I dont get the iterative total by the dates as I would like to see. It is giving me the total qty logic as if I was jusr doing a sum(qty).

Iterative Qty = sumx(values(date[date_dt]), [final Qty]) (this should add up all the values on the views itself but when I look at it, the rows are correct but the total is still wrong. I had to export it to excel and noticed its not working)

Any other way to add my iterative values for my view?
1 ACCEPTED SOLUTION  Community Champion

Hi @yve214 ``````Final Qty =
SUMX (
SUMMARIZE( Data, Data[Date], Data[Category] ),
CALCULATE (
VAR CurrentDate = MAX ( Data[Date] )
VAR OriginalQty = SUM ( Data[Original Quantity] )
VAR CurrentCategoryTable = CALCULATETABLE ( Data, ALLEXCEPT ( Data, Data[Category] ) )
VAR PreviousDatesTable = FILTER ( CurrentCategoryTable, Data[Date] < CurrentDate )
VAR PreviousDate = MAXX ( PreviousDatesTable, Data[Date] )
VAR PreviousQty = CALCULATE ( SUM ( Data[Original Quantity] ), Data[Date] = PreviousDate )
RETURN
IF (
ISBLANK ( OriginalQty ),
PreviousQty,
OriginalQty
)
)
)``````
4 REPLIES 4  Community Champion

Hi @yve214 ``````Final Qty =
SUMX (
SUMMARIZE( Data, Data[Date], Data[Category] ),
CALCULATE (
VAR CurrentDate = MAX ( Data[Date] )
VAR OriginalQty = SUM ( Data[Original Quantity] )
VAR CurrentCategoryTable = CALCULATETABLE ( Data, ALLEXCEPT ( Data, Data[Category] ) )
VAR PreviousDatesTable = FILTER ( CurrentCategoryTable, Data[Date] < CurrentDate )
VAR PreviousDate = MAXX ( PreviousDatesTable, Data[Date] )
VAR PreviousQty = CALCULATE ( SUM ( Data[Original Quantity] ), Data[Date] = PreviousDate )
RETURN
IF (
ISBLANK ( OriginalQty ),
PreviousQty,
OriginalQty
)
)
)``````  Helper II

@tamerj1 Thank you so much again for your help. This worked like magic.. Amazing!  Community Champion

Hi @yve214

what do you mean by

if(
max(date[date_dt]) =max(date[date_dt])
can you share a screenshot of your visual?  Helper II

My apologies on the delayed response. PLease see SS below. My total from this view, the final qty should be 70,609 but I am getting just 67,207. To have generated that final Qty, I used the measure listed above. I was calculating where if there is missing qty value for a date, take the qty for the previous day and subtitute.

For instance there is no quanty for category C for the date 5/28/2022, so my final Qty measure took the value from 5/27/2022 which is 3402 and filled in the gap. But this means, my final Qty now should be more than my original qty.

Here is the result data which seems to be working with the final Qty measure i calculated. BUt my sumx isnt working to give me my correct totals at the bottom.

 Date Category Original Quantity Final Qty 5/28/2022 0:00 A 2141 2141 5/28/2022 0:00 B 4227 4227 5/28/2022 0:00 C 3402 5/27/2022 0:00 A 2143 2143 5/27/2022 0:00 B 4220 4220 5/27/2022 0:00 C 3402 3402 5/26/2022 0:00 A 2143 2143 5/26/2022 0:00 B 4364 4364 5/26/2022 0:00 C 3398 3398 5/25/2022 0:00 A 1998 1998 5/25/2022 0:00 B 4381 4381 5/25/2022 0:00 C 3781 3781 5/24/2022 0:00 A 1884 1884 5/24/2022 0:00 B 4532 4532 5/24/2022 0:00 C 3470 3470 5/23/2022 0:00 A 1912 1912 5/23/2022 0:00 B 4676 4676 5/23/2022 0:00 C 3786 3786 5/22/2022 0:00 A 2141 2141 5/22/2022 0:00 B 4733 4733 5/22/2022 0:00 C 3875 3875 Announcements #### The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates. #### Ted's Dev Camp - July 28, 2022

Watch Session 24 of Ted's Dev Camp along with past sessions!  