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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
alexricker0928
Frequent Visitor

Variable in DATEADD function

I'm trying to age certain dollar amounts based on the due date of the invoice. 

I have a 'before' date filter in my report that runs the report 'as of' whatever is selected. 

 

Let's say I run the report as of 11/06/2020, I want to calculate the Balance Last 30 Days based on the date selected in the filter. I essentially want to sum the dollar amounts on all transactions that have a due date less than 11/06/2020 and greater than 10/05/2020. Here is the calculation I currently have:

 

CT Balance Last 30 Days =
VAR CurrentDate =
IF(
COUNTROWS(DISTINCT(ALLSELECTED('DimDate-InvoiceDate'[Date]))) = 1,
SELECTEDVALUE('DimDate-InvoiceDate'[Date]),
MAX('DimDate-InvoiceDate'[Date])
)

Return
CALCULATE(SUM(OpenARPrepayments[AmountMST]),
FILTER(OpenARPrepayments,
OpenARPrepayments[DueDate] < CurrentDate
&&
OpenARPrepayments[DueDate] > DATEADD(CurrentDate,-30,DAY)
)
 
 
It won't let me pass the variable into the DATEADD function, but I can't think of another way to get this to work.
 
1 ACCEPTED SOLUTION
AntrikshSharma
Super User
Super User

@alexricker0928 DATEADD is a table function and in the first argument it expects a list of dates, if for some reasons you had to go by your way you have to wrap it inside curly braces { CurrentDate }

 

try if this works:

CT Balance Last 30 Days =
VAR CurrentDate =
    SELECTEDVALUE (
        'DimDate-InvoiceDate'[Date],
        MAX ( 'DimDate-InvoiceDate'[Date] )
    )
RETURN
    CALCULATE (
        SUM ( OpenARPrepayments[AmountMST] ),
        FILTER (
            OpenARPrepayments,
            OpenARPrepayments[DueDate] < CurrentDate
                && OpenARPrepayments[DueDate] > CurrentDate - 30
        )
    )

 

View solution in original post

2 REPLIES 2
AntrikshSharma
Super User
Super User

@alexricker0928 DATEADD is a table function and in the first argument it expects a list of dates, if for some reasons you had to go by your way you have to wrap it inside curly braces { CurrentDate }

 

try if this works:

CT Balance Last 30 Days =
VAR CurrentDate =
    SELECTEDVALUE (
        'DimDate-InvoiceDate'[Date],
        MAX ( 'DimDate-InvoiceDate'[Date] )
    )
RETURN
    CALCULATE (
        SUM ( OpenARPrepayments[AmountMST] ),
        FILTER (
            OpenARPrepayments,
            OpenARPrepayments[DueDate] < CurrentDate
                && OpenARPrepayments[DueDate] > CurrentDate - 30
        )
    )

 

What if the situation requires the filter to be "CurrentDate - 1 Quarter". What can you do then? (different quarter has different number of days)

 

thank you!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.