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
Anonymous
Not applicable

Sum of Measures Returning Incorrect Value

Hi Everyone,

 

I'm stumped on this problem I'm having with a measure that is not adding up. 

 

I found this article on Measure Totals which helped me better understand the difference between row context and filter context in DAX, but I'm finding it difficult to apply the example solution to my problem.

 

As you can see, the total is not summing correctly.

 

 

PowerBIForum_MeasureProfitColumnValues.png

 This is the equation I'm using to create the MeasureProfit values.

 

PowerBIForum_MeasureProfit_Equation.png

 Any idea what I can do to receive a correct sum for the MeasureProfit caluclation?  All other columns are working as expected.

 

Thank You!

 

 

1 ACCEPTED SOLUTION

Hey,

 

Measure seems to create the specified results:

MeasureProfitFinal = 
CALCULATE( 
    SUMX(
        ADDCOLUMNS(
        SUMMARIZE('AllData'
            ,'AllData'[Client]
            ,'AllData'[Date].[Month]
            ,'AllData'[Retainer]
        )
        ,"This",[MeasureProfit])
        ,[This])
    )

Here you will a pbix file 

Here are some screenshots
Client 3.pngClient 8.pngClient 9.png

 

Hope this is what you are looking for
Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

9 REPLIES 9
TomMartens
Super User
Super User

Hey @Anonymous,

 

as @Greg_Deckler already mentioned, without knowing what's the "correct" result should look like, and telling us why, it's very difficult to provide an answer.

 

So this is also just guesswork ...

 

Whats's going on:

Each row is a substantial part of the filter context (in addition to slicers, that are there or not), except the Total Row. For this reason, I assume that the Sum (meaning over all rows visible in the table visual) of "MeasureTotalCost" is deducted from the MIN('AllData'[Retainer].

 

I guess that a Measure like this will solve your Problem, maybe it could be necessary to use AVERAGEX instead of MINX as the table iterator function

 

MeasureProfit = 
MINX(
ALLSELECTED('AllData')
,MIN('AllData'[Retainer] - [MeasureTotalCost]
)

 

Hope this gives you an idea.

Maybe you should consider to create a pbix file with sampledata, upload the file to onedrive or dropbox, and share the link with us.

 

Regards

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
Anonymous
Not applicable

All,

 

I'm attaching the .pbix with test data as @TomMartens recommended.

 

To view an example of the issue from the Report view, filter by month (January and February) and select Client 3

 

It is located here:  https://1drv.ms/f/s!Av7yMH1V07x8ogYw68C5JOz-ltPH

 

I understand it is difficult to give an answer without it.

 

Thank you for your support.

@Anonymous- Thanks for providing the PBIX file. I guess, can you give us a specific circumstance such as filtering by month (January and February and then selecting Client 3) as to what is the correct value that you would expect to see. In other words, under those circumstances, what value should be displayed in the Total line for MeasureValue?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

A few examples:

 

Selecting Client3 and date range from January to end of February, the value on the total line for MeasureProfit should be $2,700.00

 

Selecting Client8 and date range from February to end of March, the value on the total line for MeasureProfit should be $1,300.00

 

Selecting Client9 and date range from May to end of June, the value on the total line for MeasureProfit should be $6,000.00 

 

Hey,

 

Measure seems to create the specified results:

MeasureProfitFinal = 
CALCULATE( 
    SUMX(
        ADDCOLUMNS(
        SUMMARIZE('AllData'
            ,'AllData'[Client]
            ,'AllData'[Date].[Month]
            ,'AllData'[Retainer]
        )
        ,"This",[MeasureProfit])
        ,[This])
    )

Here you will a pbix file 

Here are some screenshots
Client 3.pngClient 8.pngClient 9.png

 

Hope this is what you are looking for
Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
Anonymous
Not applicable

@TomMartens this is what I was looking for!  Thank You.

 

Can you give more information on why you used the "This" statements?

Hey,

„This“ is just a the name for the new column introduced by the Table function ADDCOLUMN and finally used by the function SUMX.

I always use „funny“ names to aboid confusion with the names of real columns and measures. So, „This“ could be replaced with „Sebastian“ and the statement will still work 🙂

Regards Tom


Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
GIO200011
Frequent Visitor

It depends what you want to do. I suspect is the sum of MeasureProfit of each day. I don't know that the MeasureTotalCost do, so it's difficult to guide you.

 

Add this to your measure:

 

MeasureProfit = IF(HASONEVALUE(Date),MIN(AllData[Retainer])-[MeasureTotalCost],XXXXX)

Instead of "XXXXX", insert the measure you need. If you provide us more information, we can help you more.

 

Regards,

-Giovany

Greg_Deckler
Super User
Super User

So what should teh correct value be?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.