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
BriefStop
Frequent Visitor

Date Range From Input Parameters in Calculate DAX

DateValue
6/13/20193
6/13/20204
6/13/20217

 

I have a table of dates and values and I want to find the difference between the sum of values of a current period and a previous period which both are filtered on the same date column. Essentially I would have one sum of value that is filtered normally with a regular slicer using date and a second sum of a value that needs to be specified separately.

The final result would look like this:

Previous Period(Measure) - 6/13/2019 - 6/13/2020: 7

Current Period(Measure) - 6/13-2020 - 6/13/2021: 11

Difference between periods(Measure): 4

 

I plan to use a CALCULATE to sum the values and then apply the date filter to the previous period but I am not sure how I can set up an input parameter to do a date range just like if I was simply filtering for date.

 

Currently:

Only thing I can think of is setting up two custom input parameter tables for the Start Date and End Date and then filtering them in calculate as CALCULATE(SUM(Value), AND(Date > Start Date, Date < End Date)). This hasn't worked so far though and the filter looks very different from my regular date slicer.

 

Is there another way to do this so that it looks like a regular date slicer? How do I filter on a date range?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @BriefStop ,

I have created a simple sample , please refer to my pbix file to see if it helps you.

Create 2 measures.

Previous Period(Measure) =
VAR _1 =
    EDATE ( MAX ( 'Table'[Date] ), -12 )
VAR _2 =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Date] = _1 )
    )
VAR _3 =
    IF ( _2 = BLANK (), BLANK (), _2 + MAX ( 'Table'[Value] ) )
RETURN
    _3
Measure =
VAR _1 =
    EDATE ( MAX ( 'Table'[Date] ), 12 )
VAR _2 =
    SUMX (
        FILTER ( ALL ( 'Table' ), 'Table'[Date] = _1 ),
        [Previous Period(Measure)]
    )
VAR _3 = _2 - [Previous Period(Measure)]
RETURN
    IF ( _2 = BLANK () || [Previous Period(Measure)] = BLANK (), BLANK (), _3 )

vrongtiepmsft_0-1686796503440.png

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @BriefStop ,

I have created a simple sample , please refer to my pbix file to see if it helps you.

Create 2 measures.

Previous Period(Measure) =
VAR _1 =
    EDATE ( MAX ( 'Table'[Date] ), -12 )
VAR _2 =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Date] = _1 )
    )
VAR _3 =
    IF ( _2 = BLANK (), BLANK (), _2 + MAX ( 'Table'[Value] ) )
RETURN
    _3
Measure =
VAR _1 =
    EDATE ( MAX ( 'Table'[Date] ), 12 )
VAR _2 =
    SUMX (
        FILTER ( ALL ( 'Table' ), 'Table'[Date] = _1 ),
        [Previous Period(Measure)]
    )
VAR _3 = _2 - [Previous Period(Measure)]
RETURN
    IF ( _2 = BLANK () || [Previous Period(Measure)] = BLANK (), BLANK (), _3 )

vrongtiepmsft_0-1686796503440.png

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

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!

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.