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
23Steve32
Frequent Visitor

Date when a cumulative total measure becomes positive

Hi,

 

I have a table and I want to find the earliest date when a cumulative measure becomes positive. I've created a measure which gets the minumim date, but when aggregated gets the minimum date overall. See the table below: 

Capture.PNG

 

 

 

 

 

You can see the date in August is correct but the total date is in March. I understand why it is getting this date, but I want it to display 4/8/2017. How do I do this? 

 

**Edit: For clarity - I just want to find the date the cumulative sum became positive for use in a datediff calculation later

 

Many thanks in advance

1 ACCEPTED SOLUTION

Hi @23Steve32,

 

Try this formula please. Please note the date format of mine is different from yours. You can check it out in this file.

 

Date cashflow becomes positive 2 =
VAR cumulation =
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE (
                'Append1',
                Append1[TLJOBCDE],
                'Date'[Date].[Year],
                'Date'[Date].[MonthNo]
            ),
            "value", [Cumulative Cash Flow]
        ),
        [value] >= 0
    )
VAR targetYear =
    MINX ( cumulation, [Year] )
VAR targetMonth =
    MINX ( cumulation, [MonthNo] )
RETURN
    CALCULATE (
        MIN ( 'Append1'[THDATEPY] ),
        YEAR ( Append1[THDATEPY] ) = targetYear
            && MONTH ( Append1[THDATEPY] ) = targetMonth
    )

Date when a cumulative total measure becomes positive.png

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

9 REPLIES 9
v-jiascu-msft
Employee
Employee

Hi @23Steve32,

 

Could you please mark the proper answer as solution or share the solution if it's convenient for you? That will be a big help to the others.

 

Best Regards!
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Greg_Deckler
Super User
Super User

I am thinking that perhaps you need a calendar table and then a calculated column in that table that essentially does an IF statement and IF the measure (based upon the date) is negative, put a 0 in the column, otherwise a 1. Then you should be able to get the MIN of the date in that table?


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

I have a date table, the problem with that approach is the image I shared is one project, there are perhaps 200+ that I need to do this for, so I assume your method wouldnt work? 

Hi @23Steve32,

 

Can you share a sample please? I think you need the function SUMMARIZE to get the right answer.

 

Best Regards!

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 Hi @v-jiascu-msft,

 

I've createrd a sample file, removing the sensative data, however I cannot seem to attach the file! Probably a major oversight on my behalf but do you know how I'd do this?

 

Thanks,
Steve

Post the file on OneDrive or Box and create a share link.


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

Hi,

 

PLease find the file in the link. I've included 2 projects in the sample to give a feel for the kind of data
https://www.dropbox.com/s/06kyyi34ics47um/Cash%20flow%20sample.pbix?dl=0

 

Thanks,

Steve

Hi @23Steve32,

 

Try this formula please. Please note the date format of mine is different from yours. You can check it out in this file.

 

Date cashflow becomes positive 2 =
VAR cumulation =
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE (
                'Append1',
                Append1[TLJOBCDE],
                'Date'[Date].[Year],
                'Date'[Date].[MonthNo]
            ),
            "value", [Cumulative Cash Flow]
        ),
        [value] >= 0
    )
VAR targetYear =
    MINX ( cumulation, [Year] )
VAR targetMonth =
    MINX ( cumulation, [MonthNo] )
RETURN
    CALCULATE (
        MIN ( 'Append1'[THDATEPY] ),
        YEAR ( Append1[THDATEPY] ) = targetYear
            && MONTH ( Append1[THDATEPY] ) = targetMonth
    )

Date when a cumulative total measure becomes positive.png

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Sorry for the very late reply I've been super busy! Thank you so much for the help! 

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.