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

Calculate cumulative total for each row of the date and then plot minimum for each date

Finding it difficult to explain in words so will try with example. 

I have data as shown in black column:

Timeband ValueDisplayOrderEntityRefDtAsDate CumSumMin CumSum
0D <= 1D 1001E104-Jan-24 1000
1D <= 2D -502E104-Jan-24 50 
2D <= 3D 753E104-Jan-24 125 
3D <= 4D -1004E104-Jan-24 25 
4D <= 5D -255E104-Jan-24 0 
         
0D <= 1D 1501E105-Jan-24 15050
1D <= 2D 252E105-Jan-24 175 
2D <= 3D -753E105-Jan-24 100 
3D <= 4D -504E105-Jan-24 50 
4D <= 5D 505E105-Jan-24 100 
         
0D <= 1D 2001E106-Jan-24 20035
1D <= 2D -1002E106-Jan-24 100 
2D <= 3D 503E106-Jan-24 150 
3D <= 4D 354E106-Jan-24 185 
4D <= 5D -1505E106-Jan-24 35 
         
0D <= 1D 201E204-Jan-24 20-80
1D <= 2D 252E204-Jan-24 45 
2D <= 3D -753E204-Jan-24 -30 
3D <= 4D -504E204-Jan-24 -80 
4D <= 5D 305E204-Jan-24 -50 
         
0D <= 1D -501E205-Jan-24 -50-85
1D <= 2D -102E205-Jan-24 -60 
2D <= 3D 203E205-Jan-24 -40 
3D <= 4D -454E205-Jan-24 -85 
4D <= 5D 255E205-Jan-24 -60 
         
0D <= 1D 2001E206-Jan-24 20050
1D <= 2D -1002E206-Jan-24 100 
2D <= 3D 503E206-Jan-24 150 
3D <= 4D 504E206-Jan-24 200 
4D <= 5D -1505E206-Jan-24 50

 

 

 

For each date there are time buckets with displayorder, I want to

- first do rolling sum of 'value' for each date and time bucket,

- then find the minimum value of rolling sum

- plot this and also show which day was the minimum

 

so if filter on screen = E1, then char looks like

alsm_0-1704820288857.png

Min on 4-Jan =  "4D <= 5D"

Min on 5-Jan =  "3D <= 4D" and so on

and if filter = E2., then chart looks like

alsm_1-1704820316378.png

 

 

Tried lot os combination of summarize and filter but no luck ... any hints?

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@alsm Well, why can't you just do a MIN or MINX? Seems like a lot of extra work otherwise.

 

You could do something like this:

(1) Better Running Total - Microsoft Fabric Community

 

Based on this you should be able to do this:

CumSumMin = 
    VAR __Table = 'Table'
    VAR __Table1 = 
      ADDCOLUMNS(
        'Table',
        "CumSum", VAR __DispOrder = [DisplayOrder] RETURN SUMX(FILTER(__Table),[DisplayOrder] <= __DispOrder),[Value])
      )
RETURN
    MINX(__Table1,[CumSum])

 

 


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

View solution in original post

5 REPLIES 5
alsm
Helper III
Helper III

oh wow!

@Greg_Deckler Thank you, this was quite an easy solution to understand and implement. I looked at your video too. Very useful, thank you for that too

I have a follow up question.

I also want to show the minimum position

so I implmented additional Measure 

CumSumMin = 
    VAR __Table = 'Table'
    VAR __Table1 = 
      ADDCOLUMNS(
        'Table',
        "CumSum", VAR __DispOrder = [DisplayOrder] RETURN SUMX(FILTER(__Table),[DisplayOrder] <= __DispOrder),[Value])
      )
RETURN
    MINX(__Table1,[CumSum])
---------
CumSumMinPos = 
    VAR __Table = 'Table'
    VAR __Table1 = 
      ADDCOLUMNS(
        'Table',
        "CumSum", VAR __DispOrder = [DisplayOrder] RETURN SUMX(FILTER(__Table),[DisplayOrder] <= __DispOrder),[Value])
      )
   VAR _min_val = [CumSumMin] //Previous Measure
RETURN
   CALCULATE(MAX(Table[DisplayOrder]),FILTER(__Table1, [CumSum] = _min_val))
    

 

This works fine but see, large part of the measure code of CumSumMinPos is redundant with Measure CumSumMin. Is there a way to write it more efficiently?

Hi, @alsm 

 

Try below for cumsum min

 

Measure=

Calculate (

     Minx(

        table, [cumsum]),

        Allexcept(table, table[refdtasdate]

)

@Dangar332 , sorry totally lost  😞

What is this?

Googling: DAX **bleep**, shows a result or two with time intelligence.

Where can I read about this?

Hi, @alsm 

 

Measure=

 

Calculate (

 

     Minx(

 

        table, [cumsum]),

 

        Allexcept(table, table[refdtasdate]

 

))

Greg_Deckler
Super User
Super User

@alsm Well, why can't you just do a MIN or MINX? Seems like a lot of extra work otherwise.

 

You could do something like this:

(1) Better Running Total - Microsoft Fabric Community

 

Based on this you should be able to do this:

CumSumMin = 
    VAR __Table = 'Table'
    VAR __Table1 = 
      ADDCOLUMNS(
        'Table',
        "CumSum", VAR __DispOrder = [DisplayOrder] RETURN SUMX(FILTER(__Table),[DisplayOrder] <= __DispOrder),[Value])
      )
RETURN
    MINX(__Table1,[CumSum])

 

 


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

Power BI Monthly Update - April 2024

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

Top Solution Authors