cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
yve214
Helper II
Helper II

Sumx function isn't working for my view

Hi there,

 

please help me.

 

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
tamerj1
Community Champion
Community Champion

Hi @yve214 
Please use

1.png

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
            )
    )
)

View solution in original post

4 REPLIES 4
tamerj1
Community Champion
Community Champion

Hi @yve214 
Please use

1.png

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
            )
    )
)

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

tamerj1
Community Champion
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?

@tamerj1 

 

My apologies on the delayed response. PLease see SS below.

yve214_1-1655299960965.png

 

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.

 

DateCategoryOriginal QuantityFinal Qty
5/28/2022 0:00A21412141
5/28/2022 0:00B42274227
5/28/2022 0:00C 3402
5/27/2022 0:00A21432143
5/27/2022 0:00B42204220
5/27/2022 0:00C34023402
5/26/2022 0:00A21432143
5/26/2022 0:00B43644364
5/26/2022 0:00C33983398
5/25/2022 0:00A19981998
5/25/2022 0:00B43814381
5/25/2022 0:00C37813781
5/24/2022 0:00A18841884
5/24/2022 0:00B45324532
5/24/2022 0:00C34703470
5/23/2022 0:00A19121912
5/23/2022 0:00B46764676
5/23/2022 0:00C37863786
5/22/2022 0:00A21412141
5/22/2022 0:00B47334733
5/22/2022 0:00C38753875

Helpful resources

Announcements
August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power BI Dev Camp Session 24 without aka link and time 768x460.jpg

Ted's Dev Camp - July 28, 2022

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

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors