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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
PowerRobots99
Helper II
Helper II

DAX Challange - Filtering Date by Difference between Consecutive Dates

Hello Friends,

Please refer .PBIX and excel file saved at path below :-

https://drive.google.com/drive/folders/1Fyp8iTgi_5pe3R_AsBD5QbbmUt608LXf?usp=sharinghttps://drive.go...

 

Required Output - 

PowerRobots99_0-1728719957790.png

 

 

I am facing a DAX challange where, we have to calculate the difference between consecutive report dates, and then filter "TransScheduleCompletionDate" by that difference.

 

For example, the difference between 07-28-2024 and 08-25-2024 is 28 days, 

Hence, we have to select report date - "07-28-2024" and then filter "TransScheduleCompletionDate" column to select next 28 days starting from 07/29/2024 (Inclusive) - (29 Jul-25 Aug) and then returning count of transactions 2502 against report date

08-25-2024

 

PowerRobots99_0-1728721402513.png

 

Thank you,

Happy learning

 

 

 

 

 

1 ACCEPTED SOLUTION

@PowerRobots99  Now you have column in your table as well as you know how to calculate scheduled trans. It is very easy to develop such matrix.

However, here is your desired output:


Code Version 1:

 

ScheduledTrans1 = 
IF(
    HASONEVALUE(Data[ReportDate]),
    MAX(Data[ScheduledTrans])
)

 

Image showing matrix:

shafiz_p_3-1728790950257.png

 

Code Version 2:

 

DistinctScheduledTrans = 
IF(
    ISINSCOPE('Data'[ReportDate]),
    CALCULATE(
        MINX(
            'Data',
            [ScheduledTrans]
        )
    ),
    BLANK()
)

 

 Image showing matrix output version 2:

shafiz_p_1-1728790261711.png

 

If you don't want to create a calculated column, then try the below code:

 

DistinctScheduledTrans_V3 = 
VAR CurrentReportDate = MAX('Data'[ReportDate])

VAR PreviousDate = 
    CALCULATE(
        MAX('Data'[ReportDate]),
        FILTER(
            ALL('Data'),
            'Data'[ReportDate] < CurrentReportDate
        )
    )

VAR DateDiff = 
    DATEDIFF(
        PreviousDate, 
        CurrentReportDate, 
        DAY
    )

VAR TransactionIDCount = 
    CALCULATE(
        COUNT('Data'[Transaction ID]),
        FILTER(
            ALL('Data'),
            'Data'[TransScheduleCompletionDate] >= PreviousDate + 1 &&
            'Data'[TransScheduleCompletionDate] <= PreviousDate + DateDiff &&
            'Data'[ReportDate] = PreviousDate
        )
    )

RETURN

IF(
    ISBLANK(PreviousDate),
    BLANK(),
    IF(
        HASONEVALUE(Data[ReportDate]),
        TransactionIDCount
    )
)

 

Here is the desired output:

shafiz_p_2-1728790828597.png

 

Hope this helps!!

View solution in original post

5 REPLIES 5
shafiz_p
Super User
Super User

Hi @PowerRobots99  Try below code:

For Report Date Difference

shafiz_p_0-1728724357802.png

For CompletionDate:

shafiz_p_0-1728724671665.png

 

 

Hope this helps!!

If this solved your problem, please accept it as a solution!!

 

Best Regards,
Shahariar Hafiz

Hi @shafiz_p 

 

Thank you for your reply, appreciate it,

But, please read my question again, we need output in below form -

 

PowerRobots99_0-1728724991329.png

 

 

@PowerRobots99  Try below code to get the desired output. See image below:

shafiz_p_0-1728727264458.png

 

 

You can also create a new table from the above table by using Distinct and SelectColumns Function:

shafiz_p_0-1728727711763.png

 

If this solved your problem, please accept it as a solution and a kudos!!

 

Best Regards,

Shahariar Hafiz

@shafiz_p 

 

Thank you for the reply,

Please provide DAX output in maxtrix visual as shown 

PowerRobots99_0-1728746317934.png

 

 

@PowerRobots99  Now you have column in your table as well as you know how to calculate scheduled trans. It is very easy to develop such matrix.

However, here is your desired output:


Code Version 1:

 

ScheduledTrans1 = 
IF(
    HASONEVALUE(Data[ReportDate]),
    MAX(Data[ScheduledTrans])
)

 

Image showing matrix:

shafiz_p_3-1728790950257.png

 

Code Version 2:

 

DistinctScheduledTrans = 
IF(
    ISINSCOPE('Data'[ReportDate]),
    CALCULATE(
        MINX(
            'Data',
            [ScheduledTrans]
        )
    ),
    BLANK()
)

 

 Image showing matrix output version 2:

shafiz_p_1-1728790261711.png

 

If you don't want to create a calculated column, then try the below code:

 

DistinctScheduledTrans_V3 = 
VAR CurrentReportDate = MAX('Data'[ReportDate])

VAR PreviousDate = 
    CALCULATE(
        MAX('Data'[ReportDate]),
        FILTER(
            ALL('Data'),
            'Data'[ReportDate] < CurrentReportDate
        )
    )

VAR DateDiff = 
    DATEDIFF(
        PreviousDate, 
        CurrentReportDate, 
        DAY
    )

VAR TransactionIDCount = 
    CALCULATE(
        COUNT('Data'[Transaction ID]),
        FILTER(
            ALL('Data'),
            'Data'[TransScheduleCompletionDate] >= PreviousDate + 1 &&
            'Data'[TransScheduleCompletionDate] <= PreviousDate + DateDiff &&
            'Data'[ReportDate] = PreviousDate
        )
    )

RETURN

IF(
    ISBLANK(PreviousDate),
    BLANK(),
    IF(
        HASONEVALUE(Data[ReportDate]),
        TransactionIDCount
    )
)

 

Here is the desired output:

shafiz_p_2-1728790828597.png

 

Hope this helps!!

Helpful resources

Announcements
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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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