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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Alessandro_Scal
Frequent Visitor

SUMX + CALCULATE not working

Hi Everyone,

 

I am struggling with the following code that apparently seems quite simple:

 

Test sumx =

        SUMX(

            'Database',

        CALCULATE(

        SUM('Database'[Sales])/SUM('Database'[Quantity]), PREVIOUSMONTH('Calendar'[Date].[Date])

    )

        )

Basically, I'd like to compute the AVG price of the previous month, but I want also the results to be all summed up at every level (Customer/Item no./Business Unit). I know it does not make sense to sum up the AVG price, but this is part of a bigger code that I have already checked.

 

The formula doesn't seem to work, all I get is zeros.. but I am having an hard time figuring out why.. Here below I am attaching a snapshot of the Database I am working on.

 

Thank you!

 

Alessandro

 

Alessandro_Scal_0-1715013364801.png

 

 

 

 

9 REPLIES 9
lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Thanks, for the advice.. reposting with a proper data structure..

 

Hi Everyone,

I am struggling with the following code that apparently seems quite simple:

 
Test SUMX and CALCULATE =
 SUMX(
    Test,
    CALCULATE(
        SUM(Test[Sales])/SUM(Test[Quantity]),PREVIOUSMONTH(Test[Invoice date].[Date])
    )
 )

 

Basically, I'd like to compute the AVG price of the previous month, but I want also the results to be all summed up at every level (Customer/Item no./Business Unit). I know it does not make sense to sum up the AVG price, but this is part of a bigger code that I have already checked.

The formula doesn't seem to work, all I get is zeros.. but I am having an hard time figuring out why.. 

 

This is the database (first 10 rows):

Item no.Invoice dateMonthYearInvoice no.Business UnitProduct typeCustomer nameSalesQuantity
266111/12/20231220233078Business Unit AProduct ACustomer 126.681,7023.405,00
334609/11/2023820232181Business Unit AProduct ACustomer 29.367,647.391,00
334628/12/202322023420Business Unit AProduct ACustomer 25.044,344.234,00
339731/12/202312023134Business Unit AProduct ACustomer 32.528,15921,00
337213/11/202342023825Business Unit AProduct ACustomer 33.962,091.991,00
337009/11/2023520231113Business Unit AProduct ACustomer 34.641,393.049,00
337021/12/202322023380Business Unit AProduct ACustomer 33.909,622.734,00
210511/11/2023520231158Business Unit AProduct ACustomer 41.534,001.300,00
210515/12/2023920232249Business Unit AProduct ACustomer 53.555,202.020,00

 

This is the outcome:

Alessandro_Scal_0-1715175519296.png

Any help?!

 

Thank you!

 

Alessandro

 

PREVIOUSMONTH and all the other Time "Intelligence"  functions require a proper calendar table. 

 

lbendlin_0-1715202472418.png

 

 

 

Hi,

 

thanks for answering. I have taken your pbix file and only sliced it differently, but I keep not getting the SUMX of previous period AVG price. Please see below the screenshots, as you can see when I run the formula on current AVG price it works fine, while when I do it on previous AVG price it returns only blank values. Any clue why this is happening? Thanks!

 

Alessandro_Scal_0-1715268704083.png

Alessandro_Scal_1-1715268729190.png

Alessandro_Scal_2-1715268811772.png

 

Please provide sample data that fully covers your issue.
Please show the expected outcome based on the sample data you provided.

Here's is the pbix file and the expected output (in red).

 

Thanks

 

https://drive.google.com/file/d/19qXI6-giQpKrmzmFWLnxzsGrFYygXW4S/view?usp=sharing 

 

Alessandro_Scal_0-1715326285376.png

 

 

 

 

Link asks for access, please verify

Now it should work.. thanks

SUMX of prev Avg = CALCULATE( SUMX( 'Table',[Avg]),DATEADD('Calendar'[Date],-1,MONTH))

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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