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
Likhitha
Helper IV
Helper IV

How to calculate cumulative of sales for products by months which are consecutive positives

Hello All,

I'm having sales data for months by products.I want to calclulate cumulative of sales for N months ,if the months have positive sales.Month Selection is dynamic.In my case i'm considering for 3 months.

IMG_20191205_173704.jpg

1 ACCEPTED SOLUTION
v-frfei-msft
Community Support
Community Support

Hi @Likhitha ,

 

We can create a meausre as below.

Measure = 
VAR ed =
    EDATE ( MAX ( 'Current Year'[Date] ), -3 )
VAR d =
    MAX ( 'Current Year'[Date] )
RETURN
    CALCULATE (
        SUM ( 'Current Year'[Total Customer] ),
        FILTER (
            ALLSELECTED ( 'Current Year' ),
            'Current Year'[Date] > ed
                && 'Current Year'[Date] <= d
                && 'Current Year'[Total Customer] >= 0
        )
    )

 

Capture.PNG

 

 

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

View solution in original post

7 REPLIES 7
Likhitha
Helper IV
Helper IV

Hello All,

Thank you so much for your solutions.

I created some DAX and got the solution.

 

SalesNew= if(calculate(sum('NewData'[Sales]),DATEADD(DateTable[Date],0,MONTH))>0 &&
calculate(sum('NewData'[Sales]),DATEADD(DateT[Date],-1,MONTH))>0 &&
calculate(sum('NewData'[Sales]),DATEADD(DateTable[Date],-2,MONTH))>0 ,
CALCULATE(sum('NewData'[Sales]),FILTER(ALL(DateTable[Date]),MONTH(DateTable[Date])>MONTH(MAX(DateTable[Date]))-3 && MONTH(DateTable[Date])<=MONTH(MAX(DateTable[Date])))))
v-frfei-msft
Community Support
Community Support

Hi @Likhitha ,

 

We can create a meausre as below.

Measure = 
VAR ed =
    EDATE ( MAX ( 'Current Year'[Date] ), -3 )
VAR d =
    MAX ( 'Current Year'[Date] )
RETURN
    CALCULATE (
        SUM ( 'Current Year'[Total Customer] ),
        FILTER (
            ALLSELECTED ( 'Current Year' ),
            'Current Year'[Date] > ed
                && 'Current Year'[Date] <= d
                && 'Current Year'[Total Customer] >= 0
        )
    )

 

Capture.PNG

 

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
Tahreem24
Super User
Super User

Hi @Likhitha ,

 

Use the below measure to your calculation:

Cumulative = CALCULATE([Total],FILTER(ALLSELECTED(Table1),Table1[Month Num] <= MAX(Table1[Month Num])))

Don't forget to hit Thumbs up and accept this as a solution if you find it helpful! 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard

@Tahreem24  In my case , if i select december month the cumulative sum should happen only if my november and october months have positive values,otherwise the product should be ignored.(I'm doing cumulative for 3 months).

@Likhitha ,

 

Attached screen shot for your reference:

Capture.JPG

 

Please give KUDOS for support! 😊

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard

@Likhitha ,

 

Please try below measure:

Last 3 month Cumulative = CALCULATE(SUM('Current Year'[Total Customer]),DATESINPERIOD('Current Year'[Month],LASTDATE('Current Year'[Month]),-3,MONTH))
 
Please hit Thumbs up for support and accept this as a solution if it helps you!
Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard

@Tahreem24  In that DAX,how can i check that each month sales value is positive only??

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.