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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Gutierrez
Frequent Visitor

DateDiff with Selected Date Value

Hello, hope you all doing good. I'm trying to Calculate several measures (sales total, etc) but having a filter named "Tenure" which have two options, < 60 Days or >= 60 Days, this values needs to consider the DateDiff between the Agent's Production Date and the Date Selected from Calendar Table, i.e. Capture.PNG

 

Those are two tables, Roster and Sales, if I select from Calendar table 05/17/2022, and from Tenure filter >=60 Days it should show Agent A and Agent B with their sales (because the Tenure is based on the DateDiff bewteen the Selected Date (05/17/2022) and the Agent's Production Dates (9/10/2021 and 2/12/2022). If I select the same Date (05/17/2022) but now from Tenure <60 Days, it should show Agent C because the DateDiff is less than 60.

 

Another thing is if I select multiple values from the Calendar Table, it should consider the last one (i.e. if I select from May 1st to May 5th, the datediff should be with May 5th). 

 

I already found the way to show the correct values from my calculate measures if I select wheter < 60 Days, >= 60 Days or both for one single selected Date, the problem is when I select multiple values and it shows me everything without considering the max date selected.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Gutierrez ,

I created a sample pbix file(see the attachment), please check if that is what you want.

1. Create a measure as below to judge if the data is in the period

Flag = 
VAR _maxdate =
    MAX ( 'Calendar'[Date] )
VAR _seltenure =
    SELECTEDVALUE ( 'Tenure'[Tenure] )
VAR _selagent =
    SELECTEDVALUE ( 'Sales'[AGENT NAME] )
VAR _pdate =
    CALCULATE (
        MAX ( 'Roster'[PRODUCTION DATE] ),
        FILTER ( 'Roster', 'Roster'[AGENT NAME] = _selagent )
    )
RETURN
    IF (
        _seltenure = ">= 60 Days"
            && DATEDIFF ( _pdate, _maxdate, DAY ) >= 60,
        1,
        IF ( _seltenure = "< 60 Days" && DATEDIFF ( _pdate, _maxdate, DAY ) < 60, 1, 0 )
    )

2. Create a table visual as below screenshot and apply a visal-level filter on it with the condition (Flag is 1)

yingyinr_0-1666856727621.png

If the above one can't help you get the desired result, please provide more sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @Gutierrez ,

I created a sample pbix file(see the attachment), please check if that is what you want.

1. Create a measure as below to judge if the data is in the period

Flag = 
VAR _maxdate =
    MAX ( 'Calendar'[Date] )
VAR _seltenure =
    SELECTEDVALUE ( 'Tenure'[Tenure] )
VAR _selagent =
    SELECTEDVALUE ( 'Sales'[AGENT NAME] )
VAR _pdate =
    CALCULATE (
        MAX ( 'Roster'[PRODUCTION DATE] ),
        FILTER ( 'Roster', 'Roster'[AGENT NAME] = _selagent )
    )
RETURN
    IF (
        _seltenure = ">= 60 Days"
            && DATEDIFF ( _pdate, _maxdate, DAY ) >= 60,
        1,
        IF ( _seltenure = "< 60 Days" && DATEDIFF ( _pdate, _maxdate, DAY ) < 60, 1, 0 )
    )

2. Create a table visual as below screenshot and apply a visal-level filter on it with the condition (Flag is 1)

yingyinr_0-1666856727621.png

If the above one can't help you get the desired result, please provide more sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.