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

Get Fabric Certified for FREE during AI Skills Fest. This week only. Secure your voucher now.

Reply
gpl
Frequent Visitor

Subtract todays total from previous day total if current month

Hey yall, thanks for all the help you guys provide! Hopefully someone can tell me how to do this as I have been struggling to figure this one out. I have a table that increments sales for the month and I am trying to get daily by subracting from previous day. I also don't want it to subtract if previous day is in a different month.

 

What I have:

Date          Sales

8/28/2021 91000

8/29/2021 91500

8/30/2021 91700

8/21/2021 92200

9/1/2021   450

 

What I want:

What I Have

Date          Sales     Daily Sales

8/28/2021 91000   

8/29/2021 91500   500

8/30/2021 91700   200

8/21/2021 92200   500

9/1/2021   450       450

 

Hopefully someone can help and I appreciate all the great resources here!

 

 

1 ACCEPTED SOLUTION
smpa01
Community Champion
Community Champion

@gpl  Can you try the following which sums on the subtotal level as well

 

 

dailySales = 
SUMX (
    'fact',
    VAR _prevDate =
        MAXX (
            FILTER ( ALL ( 'fact'[Date] ), 'fact'[Date] < EARLIER ( 'fact'[Date] ) ),
            'fact'[Date]
        )
    VAR _prevMonth =
        MONTH ( _prevDate )
    VAR _currentDate =
        CALCULATE ( MAX ( 'fact'[Date] ) )
    VAR _currentMonth =
        MONTH ( _currentDate )
    VAR _prevDateSale =
        MAXX ( FILTER ( ALL ( 'fact' ), 'fact'[Date] = _prevDate ), 'fact'[Sales] )
    VAR _currentDateSale =
        CALCULATE ( SUM ( 'fact'[Sales] ) )
    VAR _diff =
        SWITCH (
            TRUE (),
            _prevMonth = BLANK (), BLANK (),
            _currentMonth = _prevMonth, _prevDateSale - _currentDateSale,
            _currentDateSale
        )
    RETURN
        IF ( _diff < 0, ABS ( _diff ), _diff + 0 )
)

 

 

smpa01_0-1632506050882.png

 

 


========================
Did I answer your question? Mark my post as a solution!
Proud to be a Super User
My Custom Visualization Projects
• Plotting Live Sound: Live Sound
• Beautiful News: Women in Parliament, Energy Mix, Shrinking Armies
• Visual Capitalist: Working Hrs
• Others: Easing Graph, Animated Calendar
MayViz Submissions
• Week 1: View
• Week 2: View
• Week 3: View
• Week 4: View
========================

View solution in original post

3 REPLIES 3
smpa01
Community Champion
Community Champion

@gpl  Can you try the following which sums on the subtotal level as well

 

 

dailySales = 
SUMX (
    'fact',
    VAR _prevDate =
        MAXX (
            FILTER ( ALL ( 'fact'[Date] ), 'fact'[Date] < EARLIER ( 'fact'[Date] ) ),
            'fact'[Date]
        )
    VAR _prevMonth =
        MONTH ( _prevDate )
    VAR _currentDate =
        CALCULATE ( MAX ( 'fact'[Date] ) )
    VAR _currentMonth =
        MONTH ( _currentDate )
    VAR _prevDateSale =
        MAXX ( FILTER ( ALL ( 'fact' ), 'fact'[Date] = _prevDate ), 'fact'[Sales] )
    VAR _currentDateSale =
        CALCULATE ( SUM ( 'fact'[Sales] ) )
    VAR _diff =
        SWITCH (
            TRUE (),
            _prevMonth = BLANK (), BLANK (),
            _currentMonth = _prevMonth, _prevDateSale - _currentDateSale,
            _currentDateSale
        )
    RETURN
        IF ( _diff < 0, ABS ( _diff ), _diff + 0 )
)

 

 

smpa01_0-1632506050882.png

 

 


========================
Did I answer your question? Mark my post as a solution!
Proud to be a Super User
My Custom Visualization Projects
• Plotting Live Sound: Live Sound
• Beautiful News: Women in Parliament, Energy Mix, Shrinking Armies
• Visual Capitalist: Working Hrs
• Others: Easing Graph, Animated Calendar
MayViz Submissions
• Week 1: View
• Week 2: View
• Week 3: View
• Week 4: View
========================
gpl
Frequent Visitor

Your a genius; is it possible if I put that measure in a table to get it to sum just those values? It is summing for TotalSales. Ideally the table to the right would show $14249

 

gpl_0-1632502470148.png

 

 

 

DataInsights
Super User
Super User

@gpl,

 

Try these measures:

 

Total Sales = SUM ( Table1[Sales] )

Daily Sales = 
VAR vDate =
    MAX ( Table1[Date] )
VAR vMinDate =
    CALCULATE ( MIN ( Table1[Date] ), ALLSELECTED ( Table1[Date] ) )
VAR vCurrentMonth =
    MONTH ( vDate )
VAR vCurrentAmount = [Total Sales]
VAR vPrevAmount =
    CALCULATE (
        [Total Sales],
        Table1[Date] = vDate - 1,
        MONTH ( Table1[Date] ) = vCurrentMonth
    )
VAR vResult =
    SWITCH (
        TRUE (),
        vDate = vMinDate, BLANK (),
        ISBLANK ( vPrevAmount ), vCurrentAmount,
        vCurrentAmount - vPrevAmount
    )
RETURN
    vResult

 

DataInsights_0-1632491693070.png

I assumed the 8/21/2021 date should be 8/31/2021.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.