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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ajbogle
Helper I
Helper I

Comparing multiple dates with multiple tables

Hi folks,

 

I've been working on a problem for about a day and can't seem to wrap my head around a working solution.

 

Problem: We use Dialpad which is a VOIP software for our Project Managers. I need to determine if a Call or Text happened between certain dates, so this will be used for about 6 different occurences. But for the sake of trying to solve this, we can stick to the first occurence which is our Welcome Call.

 

Operations Table

Start Date = Site Survey Approved

End Date = +7 days from the Approved Timestamp

 

Call Record Table

call_date_started = When the call took place

 

These two tables are joined together based off the phone number which is the primary key for the Call Record and FK for the Operations table. When they are joined, I can bring over the PK from the Operations table which is called [RID].

 

I'm trying to determine a Yes or No = Did the call happen within the Start Date and End Date (7 days)

 

 

 

1 ACCEPTED SOLUTION
Mikelytics
Resident Rockstar
Resident Rockstar

Hi @ajbogle,

 

Base on the input you gave the following approach should to it. But since you say there are more requriements I do not know whether it will cover it end-2-end. 🙂

 

Please find below my example data:

 

Operations Table:

Mikelytics_0-1668718755404.png

 

Record Table:

 

Please be aware that the column FYI is only for your information about which call is in time, before or after. It will not be used in the further calculation.

Mikelytics_1-1668718775734.png

 

Number Table (Dimension):

Mikelytics_2-1668718857947.png

Data Model:

Mikelytics_3-1668718886693.png

 

Measure: 

Calls In Time = 

SUMX(
    VALUES(Dim_TelephoneNumber[PK_TelNumber]),

        var var_StartTime = CALCULATE(MAX(Operations[Start Date]))
        var var_EndTime = CALCULATE(MAX(Operations[End Date]))
        var var_CallTime = CALCULATE(MAX('Call Records'[call_date_started]))

        RETURN

        IF(var_CallTime >= var_StartTime && var_CallTime <= var_EndTime, 1,0)

)

 

Result:

with 3 calls in time. The SUMX makes sure that you have the right total.

Mikelytics_4-1668718971277.png

 

Additional Comment:

When there are further attributes like call type or something else which change the granularity it might be nexessary to do adjustments in the measure. But absed on your input and the understanding I got from it this should do the job or lead you to the result. 🙂

 

Best regards

Michael

-----------------------------------------------------

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

@ me in replies or I'll lose your thread.

 

 

 

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

View solution in original post

4 REPLIES 4
Mikelytics
Resident Rockstar
Resident Rockstar

Hi @ajbogle,

 

Base on the input you gave the following approach should to it. But since you say there are more requriements I do not know whether it will cover it end-2-end. 🙂

 

Please find below my example data:

 

Operations Table:

Mikelytics_0-1668718755404.png

 

Record Table:

 

Please be aware that the column FYI is only for your information about which call is in time, before or after. It will not be used in the further calculation.

Mikelytics_1-1668718775734.png

 

Number Table (Dimension):

Mikelytics_2-1668718857947.png

Data Model:

Mikelytics_3-1668718886693.png

 

Measure: 

Calls In Time = 

SUMX(
    VALUES(Dim_TelephoneNumber[PK_TelNumber]),

        var var_StartTime = CALCULATE(MAX(Operations[Start Date]))
        var var_EndTime = CALCULATE(MAX(Operations[End Date]))
        var var_CallTime = CALCULATE(MAX('Call Records'[call_date_started]))

        RETURN

        IF(var_CallTime >= var_StartTime && var_CallTime <= var_EndTime, 1,0)

)

 

Result:

with 3 calls in time. The SUMX makes sure that you have the right total.

Mikelytics_4-1668718971277.png

 

Additional Comment:

When there are further attributes like call type or something else which change the granularity it might be nexessary to do adjustments in the measure. But absed on your input and the understanding I got from it this should do the job or lead you to the result. 🙂

 

Best regards

Michael

-----------------------------------------------------

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

@ me in replies or I'll lose your thread.

 

 

 

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

Brilliant! This work perfectly, I had the seperate Phone table but I never thought to reference both the Ops/Call record table.

Cheers!

Hi @ajbogle ,

 

Awesome and thanky you for your feedback! 🙂 This is one of the gret benefits of using a starschema model (Understand star schema and the importance for Power BI - Power BI | Microsoft Learn). Your oeprations and record tables are fact tables and the phone table is a dimension tables. You can connect multiple fact tables to your dimension tables using a key which enebales you to do cross-tables calculation for this key. It is also common to have multiple dimensions tables connectiing to mutliple fact tables which enables more detailed cross-table analysis.

 

Best regards

Michael

-----------------------------------------------------

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

@ me in replies or I'll lose your thread.

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!
AllisonKennedy
Super User
Super User

@ajbogle  I'm not sure how Phone number is a PK, but if that's the case, you can work in the Operations table and add a new column using the RELATED function. Something like:

 

Welcome Call In Dates = 

IF( RELATED(CallRecord[call_date_started]) >= Operations[approvedtimestamp] && RELATED(CallRecord[call_date_started]) <= Operations[approvedtimestamp] + 7,

"Yes",

"No"

)


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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