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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
JohnYeldham
Frequent Visitor

Peculiar differences in cumulative sum measures - trying to get cumulative profit by project

I have developed a measure for profit (SUM(revenue) - SUM(cost), as expected) that works just fine.  As expected, the measure aggregates according to the aggregate rows in output tables (e.g. if Project and Period is shown then the measure sums over Project and Period, but if only Period is shown then the measures sums over Period only).

 

The issue is that a measure I have made for CUMULATIVE profit does not work in the same consistent manner.  The columns in output tables affect how it works, yielding different - and wrong - results depending on columns chosen.

 

I have tried two different measures as  follows:

Cumulative Profit (with project constraint)

Cumulative 1 = CALCULATE([Profit], FILTER(ALLSELECTED(Table), Table[Period]<=MAX(Table[Period])))

 

Cumulative Profit (no project constraint)

Cumulative 2 = CALCULATE([Profit], FILTER(ALLSELECTED(Table), Table[Period]<=MAX(Table[Period]) && Table[Project] = MAX(Table[Project])))

 

Whether each gives the right answer depends on whether the output table shows project or not.  These mock-ups show the behaviour:

 

Capture3.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Correct (desired) cumulative balances are in green, wrong answers are in red. 

 

It is weird that one solution works when the Project is a column in the output table, and one solution works when it is not.  For the Profit measure, it works whatever the columns in the output table.

 

Anyone know how to fix it?

 

Cheers

 

John

2 REPLIES 2
amitchandak
Super User
Super User

@JohnYeldham , refer if this can help

https://www.kasperonbi.com/use-isinscope-to-get-the-right-hierarchy-level-in-dax/

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Greg_Deckler
Super User
Super User

@JohnYeldham - Would love to have some sample data to test with in order to see if I could come up with a solution that works for both. Can you post some sample data?

 

Overall though, I am not necessarily suprised, measures are finicky when it comes to context. Just think about the measures total problem. You could put them into a single measure like this:

Cumulative Profit =
  IF(
    ISINSCOPE('Table'[Project]),
    [Cumulative 1],
    [Cumulative 2]
  )


Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.