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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Raj12
Helper II
Helper II

Calculated column based on ID match between two table and time comparison

Calculated column needs to created in transaction table1 if its Unique ID match with the call data table 2 unique ID and call was made within 10mins before the transaction time
Table1 : Transaction Table

Agent Transaction DateTimeUnique ID
A46-14/01/202210:40:00A46-14/01/2022-10:40:00
A16-15/01/202216:00:00A16-15/01/2022-16:00:00
A12-16/01/202214:00:00A16-16/01/2022-14:00:00

 

Table2 : Call Table

Agent Call DateTimeUnique IDValue
A46-14/01/202210:30:00A46-14/01/2022-10:20:00Pause
A46-14/01/202210:45:00A46-14/01/2022-10:20:00No Pause
A16-15/01/202216:02:00A16-15/01/2022-16:00:00Pause
A16-15/01/202216:03:00A16-15/01/2022-16:00:00Pause
A12-16/01/202213:58:00A16-16/01/2022-14:00:00Pause
A12-16/01/202214:02:00A16-16/01/2022-14:00:00No Pause

 

Output in Table1 : new calcualted column added in the table based on reason 

Agent Transaction DateTimeUnique IDoutputReason
A46-14/01/202210:40:00A46-14/01/2022-10:40:00Pause  As Transaction table1 has entry at 10:40:00 i.e. 10 mins after call time in table 2 hence Pause is okay
A16-15/01/202216:00:00A16-15/01/2022-16:00:00No Pause  As Transaction table1 has entry at 16:00:00 i.e. 2 mins before call time in table 2 so not considered
A12-16/01/202214:00:00A16-16/01/2022-14:00:00Pause  As Transaction table1 has entry at 14:00:00 i.e. 2 mins after call time in table 2 hence Pause

 

It would be really great if anyone can suggest on this.
Thanks

1 ACCEPTED SOLUTION

Hi,

Write these calculated column formulas

Pause entries within half an hour prior = CALCULATE(COUNTROWS(Agent),FILTER(Agent,Agent[Agent]=EARLIER('Transaction'[Agent])&&Agent[Transaction Date]=EARLIER('Transaction'[Transaction Date])&&Agent[Time]<=EARLIER('Transaction'[Time])&&Agent[Time]>=EARLIER('Transaction'[Time])-time(0,30,0)&&Agent[Value]="Pause"))
Farthest time stamp in the agent table prior to the time stamp in this table = CALCULATE(max(Agent[Time]),FILTER(Agent,Agent[Agent]=EARLIER('Transaction'[Agent])&&Agent[Transaction Date]=EARLIER('Transaction'[Transaction Date])&&Agent[Time]<=EARLIER('Transaction'[Time])))
Reuslt = if('Transaction'[Farthest time stamp in the agent table prior to the time stamp in this table]=BLANK(),"Missing",if('Transaction'[Pause entries within half an hour prior]=BLANK(),"No pause","Pause"))

Ashish_Mathur_0-1701862661799.png

 


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

View solution in original post

16 REPLIES 16
Ashish_Mathur
Super User
Super User

Hi,

Write these calculated column formulas in the Transaction table.

Previous call = CALCULATE(MAX('Call'[Time]),FILTER('Call','Call'[Agent]=EARLIER('Transaction'[Agent])&&'Call'[Call Date]=EARLIER('Transaction'[Transaction date])&&'Call'[Time]<=EARLIER('Transaction'[Time])))
Output = if('Transaction'[Time]-'Transaction'[Previous call]<=TIME(0,10,0),"Pause","No pause")

Hope this helps.

Ashish_Mathur_0-1700956010231.png

 


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

Hi Ashish,
Thank you for your response.
Can you please suggest how is this accounting for Table2: Call Table column Value Pause/No Pause?
Sorry if I missed it initially but , Calculated column needs to created in transaction table1 if its Unique ID match with the call data table 2 unique ID and call was made within 10mins before the transaction time , and output column should have respective Call Table column Value 


What happens when you use my formula?  Is my result incorrect?


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

Hi Ashish,

Final result should be driven by table 2 Value column i.e. if all matching conditions are met then output sould show Table 2 Value column respective data of Pause/No Pause instaed of below logic which shows if condition is met its "Pause" , if not its "No Pause"

Output = if('Transaction'[Time]-'Transaction'[Previous call]<=TIME(0,10,0),"Pause","No pause")

 

Share the download link of the PBI file with my calculated column formulas already written there.


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

Sorry, I can't see any option in there to add an pbix file.

Raj12_0-1701084827122.png

 

Try this calculated column formula

Output = if(ISBLANK('Transaction'[Previous call]),"No pause",CALCULATE(MAX('Call'[Value]),FILTER('Call','Call'[Agent]=EARLIER('Transaction'[Agent])&&'Call'[Call Date]=EARLIER('Transaction'[Transaction date])&&'Call'[Time]=EARLIER('Transaction'[Previous call]))))

Hope this helps.

Ashish_Mathur_0-1701086017411.png

 


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

Hi Ashish,

 

Thank you for the response.
Its working fine in comparing last call from Call table with transaction table.
If comparsion is needed for any call made (Call table) is within 30 mins before the transaction time (Transaction Table) and then return OUTPUT if call table has any Pause (within last 30 mins) , if not then if it has No Pause  

Hi,

You have completely changed the requirement.  For this new one, share some data to work with and show the expected result clearly.


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

Hi Ashish,
Thank you so much for the help.
Logic:  If call made (Call table) is within 30 mins before the matching transaction time (Transaction Table) and then return OUTPUT column if call table has any Pause (within last 30 mins) , if not then if it has only No Pause then output No Pause, else no matching calls in last 30 mins then Missing
Please find below 

Raj12_0-1701771899275.png

 

Data :

Table1 : Transaction Table    
Agent Transaction DateTimeUnique ID  
A46-14/01/202210:40:00A46-14/01/2022-10:40:00  
A16-15/01/202216:00:00A16-15/01/2022-16:00:00  
A12-16/01/202214:00:00A16-16/01/2022-14:00:00  
     
Table2 : Call Table    
Agent Call DateTimeUnique IDValue 
A46-14/01/202210:30:00A46-14/01/2022-10:20:00Pause 
A46-14/01/202210:45:00A46-14/01/2022-10:20:00No Pause 
A46-14/01/202210:28:00A46-14/01/2022-10:20:00No Pause 
A16-15/01/202215:58:00A16-15/01/2022-16:00:00No Pause 
A16-15/01/202215:28:00A16-15/01/2022-16:00:00No Pause 
A16-15/01/202215:38:00A16-15/01/2022-16:00:00No Pause 
A12-16/01/202214:01:00A16-16/01/2022-14:00:00Pause 
A12-16/01/202214:02:00A16-16/01/2022-14:00:00No Pause 
     
New Column in Transaction Table   
Agent Transaction DateTimeUnique IDoutputReason
A46-14/01/202210:40:00A46-14/01/2022-10:40:00Pause  As Transaction table1 has entry at 10:40:00 and 30 mins before that call table has one entry of Pause hence output Pause
A16-15/01/202216:00:00A16-15/01/2022-16:00:00No Pause  As Transaction table1 has entry at 16:00:00 and 30 mins before that call table has only entry of entry of No Pause hence o/p No Pause
A12-16/01/202214:00:00A16-16/01/2022-14:00:00Missing  As Transaction table1 has entry at 14:00:00 i.e. no call before that time in table 2 hence output is Missing

Hi,

Write these calculated column formulas

Pause entries within half an hour prior = CALCULATE(COUNTROWS(Agent),FILTER(Agent,Agent[Agent]=EARLIER('Transaction'[Agent])&&Agent[Transaction Date]=EARLIER('Transaction'[Transaction Date])&&Agent[Time]<=EARLIER('Transaction'[Time])&&Agent[Time]>=EARLIER('Transaction'[Time])-time(0,30,0)&&Agent[Value]="Pause"))
Farthest time stamp in the agent table prior to the time stamp in this table = CALCULATE(max(Agent[Time]),FILTER(Agent,Agent[Agent]=EARLIER('Transaction'[Agent])&&Agent[Transaction Date]=EARLIER('Transaction'[Transaction Date])&&Agent[Time]<=EARLIER('Transaction'[Time])))
Reuslt = if('Transaction'[Farthest time stamp in the agent table prior to the time stamp in this table]=BLANK(),"Missing",if('Transaction'[Pause entries within half an hour prior]=BLANK(),"No pause","Pause"))

Ashish_Mathur_0-1701862661799.png

 


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

Thannk you so much for you help and providing solution for this

Hi Ashish, Whenever possible can you please suggest on the above/

Thank you

Hi,

As requested, share the download link.  Upload the file to Google Drive or a similar file hosting service and share the download link.

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Sahir_Maharaj
Super User
Super User

Hello @Raj12,

 

Can you please try this DAX :

Output = 
VAR TransactionTime = Table1[Time]
VAR TransactionDate = Table1[Transaction Date]
VAR TransactionDateTime = TransactionDate + TIME(HOUR(TransactionTime), MINUTE(TransactionTime), SECOND(TransactionTime))
VAR UniqueID = Table1[Unique ID]

VAR CallDateTime = 
    CALCULATE(
        MAX(Table2[Call Date Time]),
        FILTER(
            Table2,
            Table2[Unique ID] = UniqueID &&
            DATEDIFF(Table2[Call Date Time], TransactionDateTime, MINUTE) >= -10 &&
            DATEDIFF(Table2[Call Date Time], TransactionDateTime, MINUTE) <= 0
        )
    )

VAR Reason = 
    IF(
        ISBLANK(CallDateTime),
        "No Pause",
        LOOKUPVALUE(Table2[Value], Table2[Unique ID], UniqueID, Table2[Call Date Time], CallDateTime)
    )

RETURN
Reason

Should you require any questions, please do not hesitate to reach out to me.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution?
➤ Lets connect on LinkedIn: Join my network of 13K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Hi Sahir,
Thank you for your response.

Can you please suggest how is this accounting for Table2: Call Table column Value Pause/No Pause?

Sorry if I missed it initially but , Calculated column needs to created in transaction table1
if its Unique ID match with the call data table 2 unique ID and
call was made within 10mins before the transaction time , and
output column should have respective mathcing Call Table column Value of Pause/No Pause

Thank you for the help in advance

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Users online (825)