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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
jcawley
Helper III
Helper III

Calculated column between two dates problem

Good morning all,

 

I’m having a problem with a calculated column! My goal is to flag customers that had an appointment after being contacted sometime 90 days before the appointment up to the day of the appointment.

 

I’m using two tables.  The Appointments Table table where the calculated column is, and a Customer table that has contact records.

Appointment Table 
Unique IDAppointment DateDesired output
1239/2/20211
2345/1/20211
3452/1/20210
4562/1/20210
1235/1/20210

 

Customer Table
Unique IDCall Date
1239/1/2021
2344/1/2021
3459/1/2020
4562/5/2021
12312/1/2019
12312/1/2018
12312/1/2017


My calculated column looks like this so far:

 

Column 09022021 =

VAR APTDateMIN = Appointments Table[Appointment Date] - 90

VAR APTDate = Appointments Table[Appointment Date]

VAR APTPT = Appointments Table[Unique ID]

RETURN

    CALCULATE (

        DISTINCTCOUNT ( Appointments Table[Unique ID] ),

          FILTER(Customer Table,Customer Table[Unique ID]=APTPT

            && APTDateMIN<= Customer Table[Call Date]

            && Customer Table[Call Date] <= Appointments Table[Appointment Date]))

 

What happens when I use this is it only finds dates that = the exact date on both ends. It isn’t showing dates that occur in between the range. Only equals the exact date. Any help would be appreciated!

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@jcawley,

 

Try this solution.

 

1. Create a table with distinct customers. Calculated table:

 

CustomerMaster = 
DISTINCT (
    UNION (
        DISTINCT ( Appointment[Unique ID] ),
        DISTINCT ( CustomerCall[Unique ID] )
    )
)

 

2. Create relationships:

 

DataInsights_0-1630624397129.png

 

3. Create calculated column in Appointment table:

 

Flag = 
VAR vAptDate = Appointment[Appointment Date]
VAR vAptDateMin = Appointment[Appointment Date] - 90
VAR vRowCount =
    CALCULATE (
        COUNTROWS ( RELATEDTABLE ( CustomerCall ) ),
        CustomerCall[Call Date] > vAptDateMin,
        CustomerCall[Call Date] <= vAptDate
    )
VAR vResult =
    IF ( vRowCount > 0, 1, 0 )
RETURN
vResult

 

DataInsights_1-1630624463471.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

4 REPLIES 4
v-kkf-msft
Community Support
Community Support

Hi @jcawley ,

 

Please create an inactive relationship between Appointment and Customer table.

 

image.png

 

Then try the following formula:

Column 09022021 = 
VAR APTDateMIN = 'Appointment Table'[Appointment Date] - 90
VAR APTDate = 'Appointment Table'[Appointment Date]
VAR APTPT = 'Appointment Table'[Unique ID]
RETURN
    CALCULATE (
        DISTINCTCOUNT ( 'Appointment Table'[Unique ID] ),
        FILTER (
            'Customer Table',
            'Customer Table'[Unique ID] = APTPT
                && APTDateMIN <= 'Customer Table'[Call Date]
                && 'Customer Table'[Call Date] <= 'Appointment Table'[Appointment Date]
        ),
        USERELATIONSHIP ( 'Appointment Table'[Unique ID], 'Customer Table'[Unique ID] )
    )

vkkfmsft_0-1630912279146.png

 


If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

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

 

jcawley
Helper III
Helper III

Good morning Wizards,

 

I’m having a problem with a calculated column! The problem is trying to filter dates on a related table that are between 90 days before an appointment, and the date of the appointment.

 

I’m using two tables. The main table that has appointment data where the calculated column is, and a table that has contact records regarding customer data.

My calculated column looks like this so far:

 

 

Measure 083121 =

VAR APTDateMIN = ‘Appointments’[Appt Date] - 90

VAR APTDate = ‘Appointments’[Appt Date]

VAR APTID = ‘Appointments’[Unique Customer ID]

RETURN

    CALCULATE (

        DISTINCTCOUNT ( 'Appointments'[Unique Customer ID] ),

        ‘Appointments’[Saved Status] <> BLANK ()

            && ‘Appointments’[Saved Status] <> "Active"

            && ‘Appointments’[Saved Status] <> "New",

        Contact Record Table[Unique Customer ID] = APTID

            && Contact Record Table[status] <> "Deceased"

            && Contact Record Table[status] <> "Unreachable",

        FILTER (

            Contact Record Table,

            AND (

                APTDateMIN <= Contact Record Table[contact date],

                Contact Record Table[contact date] <= APTDate

            )

        )

    )

 

What happens when I use this is it only finds dates that = the exact date on both ends. It isn’t showing dates that occur in between the range. Only equals the exact date. If I remove the = signs nothing populates! Any help would be appreciated.

Attempting again in another thread. Added tables this time and took some data out to simplify problem. 

https://community.powerbi.com/t5/Desktop/Calculated-column-between-two-dates-problem/m-p/2054705#M76...

DataInsights
Super User
Super User

@jcawley,

 

Try this solution.

 

1. Create a table with distinct customers. Calculated table:

 

CustomerMaster = 
DISTINCT (
    UNION (
        DISTINCT ( Appointment[Unique ID] ),
        DISTINCT ( CustomerCall[Unique ID] )
    )
)

 

2. Create relationships:

 

DataInsights_0-1630624397129.png

 

3. Create calculated column in Appointment table:

 

Flag = 
VAR vAptDate = Appointment[Appointment Date]
VAR vAptDateMin = Appointment[Appointment Date] - 90
VAR vRowCount =
    CALCULATE (
        COUNTROWS ( RELATEDTABLE ( CustomerCall ) ),
        CustomerCall[Call Date] > vAptDateMin,
        CustomerCall[Call Date] <= vAptDate
    )
VAR vResult =
    IF ( vRowCount > 0, 1, 0 )
RETURN
vResult

 

DataInsights_1-1630624463471.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.