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
yve214
Helper III
Helper III

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
Super User
Super User

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
Super User
Super User

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
Super User
Super User

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

Top Solution Authors