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
Anonymous
Not applicable

Slicer MAX date minus 1 month

I'm trying to get a beginning balance. The Ending balance was simple but I dont think my logic is working for MAX minus 1 month..

 

Ending Balance = 
VAR
    vFirstDate = DATEVALUE("01/01/2000")
VAR
    vLastDate = MAX('TransactionTable'[DateColumn])
RETURN
    CALCULATE(
            SUM(TransactionTable[AmountColumn]),
                'TransactionTable'[DateColumn]>=vFirstDate
                && 'TransactionTable'[DateColumn]<=vLastDate)

This does not work.

 

Ending Balance = 
VAR
    vFirstDate = DATEVALUE("01/01/2000")
VAR
    vLastDate = MAX('TransactionTable'[DateColumn])
RETURN
    CALCULATE(
            SUM(TransactionTable[AmountColumn]),
                'TransactionTable'[DateColumn]>=vFirstDate
                && DATEADD('TransactionTable'[DateColumn]<=vLastDate,-1,MONTH))

How do I get a beginning balance?

Thank you,

 

3 REPLIES 3
AlB
Super User
Super User

Hi @Anonymous

 

What exactly would be a "beginning balance"? 

Which one of the two versions you show is not working and what's the problem?

Showing the tables in your model would certainly be helpful.

Anonymous
Not applicable

My appologies. That's what I get for copy and paste. <smile>

The second code is not working and should read Opening Balance = ...

In the last line I added the "DATEADD" portion to try and reduce the vLastDate value by one month. The first code gives me the sum of the amount column from 1/1/2000 to the last date in the slicer. I need the amount from 1/1/200 to the last day of the previous month the slicer shows.

Hi @Anonymous

 

You may refer to below measure:

Ending Balance2 =
VAR vFirstDate =
    DATEVALUE ( "01/01/2000" )
VAR vLastDate =
    MAX ( 'TransactionTable'[DateColumn] )
VAR Pre_Month =
    DATE ( YEAR ( vLastDate ), MONTH ( vLastDate ) - 1, DAY ( vLastDate ) )
RETURN
    CALCULATE (
        SUM ( TransactionTable[AmountColumn] ),
        'TransactionTable'[DateColumn] >= vFirstDate
            && 'TransactionTable'[DateColumn] <= Pre_Month
    )

Regards,

Cherie

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

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.