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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Abhishek8895
Helper I
Helper I

Can anyone help me with a DAX or any solution to calculate concurrent chats from a chat database?

I am using a DAX function as below but this is not retuning correct value as even though an agent is in 2/3 chats at the same time (before the end of earlier chat), the measure only shows as 1. How to fix?

 

Concurrent Chat = COUNTROWS(FILTER(data,data[Agent Connected On]>=EARLIER(data[Agent Connected On])&&data[Terminated On]<=EARLIER(data[Terminated On])))
 
See screenshot or let me know for any questionsConcurrent Chat.PNGDAX.PNG
18 REPLIES 18
v-jingzhang
Community Support
Community Support

Hi @Abhishek8895 

 

You can create a calculated column with this DAX

Count of Concurrent Chat = 
COUNTROWS (
    FILTER (
        'Table',
        (
            'Table'[Chat Initiated On] < EARLIER ( 'Table'[Chat Initiated On] )
                && 'Table'[Chat Terminated On] > EARLIER ( 'Table'[Chat Initiated On] )
        )
            || (
                EARLIER ( 'Table'[Chat Terminated On] ) > 'Table'[Chat Initiated On]
                    && 'Table'[Chat Initiated On] > EARLIER ( 'Table'[Chat Initiated On] )
            )
    )
) + 1

vjingzhang_0-1659089784613.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Hello, 

 

I am afraid it doesnt work, can you please check once and guide.

Also, please bear in mind that the objective is, we find that on any particular interval, was the agent was (Assigned agent) in 1, 2 or 3 chat as a concurrency

Snap 1.PNGSnap 2.PNGSnap 3.PNG

Hi @Abhishek8895 

 

Can you please provide some dummy data to show the table you have? Is [Assigned Agent] column located in the same table as the [Chat initiated on] & [Terminated on] columns? In addition, please provide the expected output based on the dummy data as well as the logic to get there.

 

As of now I guess that you want to use a slicer to switch the Assigned Agent and show the count of concurrent chats for every chat period of that person. Assume all data is from the same table, I add a new column to that table with below code. Then in the table visual, select Sum instead of Count for the [Count of Concurrent Chat] column. 

Count of Concurrent Chat = 
COUNTROWS (
    FILTER (
        'Table',
        'Table'[Assigned Agent] = EARLIER ( 'Table'[Assigned Agent] )
            && (
                (
                    'Table'[Chat Initiated On] < EARLIER ( 'Table'[Chat Initiated On] )
                        && 'Table'[Chat Terminated On] > EARLIER ( 'Table'[Chat Initiated On] )
                )
                    || (
                        EARLIER ( 'Table'[Chat Terminated On] ) > 'Table'[Chat Initiated On]
                            && 'Table'[Chat Initiated On] > EARLIER ( 'Table'[Chat Initiated On] )
                    )
            )
    )
) + 1

vjingzhang_0-1659321412108.png

 

Download the attached pbix to see if it can meet your need. If it's still not what you want, I may have misunderstood your requirement. Please provide dummy data I required in the first paragraph above to help me understand your objective clearly. 

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Thanks, the solution looks better now but still not completely fixed as if an agent has taken a chat late at night and it extends to the following day, the current code takes it as earlier and gives wrong value.. Can you check , attached is a screenshot.

 

There is no way I can actually add the PBIX file that I have so that you could see, but if you could let me know a way, I am happy to share.. 

 

For now attached imageSNAP.PNG

Hi @Abhishek8895 

 

You can refer to this blog about the several methods of providing sample data https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-... 

 

From the screenshot I cannot get where it is wrong. When you share some dummy data, can you provide the correct result along with it? In this way, I can compare my output with the correct result to varify it's correct or wrong. Take care that you should remove sensitive data like email account, names, addresses from the sample data before sharing. You can mock up some dummy data. 

 

Best Regards,
Community Support Team _ Jing

Thank you so much for looking into it and sharing this excellent tip, I was not aware.

Kindly find the table and I shall await your feedback

Assigned AgentAgent Connected OnTerminated On
gupta.sumit-s@xyz.com7/18/2022 11:54:10 PM7/19/2022 12:19:01 AM
gupta.sumit-s@xyz.com7/18/2022 11:47:29 PM7/19/2022 12:12:15 AM
gupta.sumit-s@xyz.com7/18/2022 11:47:27 PM7/19/2022 12:31:23 AM
pradeepkumar.pandey@xyz.com7/18/2022 11:45:22 PM7/19/2022 12:24:02 AM
areli.faz-sanchez@xyz.com7/18/2022 11:24:41 PM7/18/2022 11:52:25 PM
pradeepkumar.pandey@xyz.com7/18/2022 11:20:55 PM7/18/2022 11:52:36 PM
pradeepkumar.pandey@xyz.com7/18/2022 11:16:07 PM7/18/2022 11:45:08 PM
pradeepkumar.pandey@xyz.com7/18/2022 11:11:27 PM7/18/2022 11:47:56 PM
aditya.tiwari@xyz.com7/18/2022 11:07:59 PM7/18/2022 11:30:00 PM
aditya.tiwari@xyz.com7/18/2022 11:02:07 PM7/18/2022 11:29:54 PM
----7/18/2022 11:29:54 PM
areli.faz-sanchez@xyz.com7/18/2022 10:53:14 PM7/18/2022 11:03:28 PM
piyush.gade@xyz.com7/18/2022 10:47:21 PM7/18/2022 10:52:50 PM
krishna.vitekar@xyz.com7/18/2022 10:46:37 PM7/18/2022 11:34:26 PM
krishna.vitekar@xyz.com7/18/2022 10:41:54 PM7/18/2022 11:10:33 PM
pradeepkumar.pandey@xyz.com7/18/2022 10:29:30 PM7/18/2022 10:49:46 PM
pradeepkumar.pandey@xyz.com7/18/2022 10:27:24 PM7/18/2022 10:45:28 PM
gupta.sumit-s@xyz.com7/18/2022 10:20:56 PM7/18/2022 11:13:04 PM
pradeepkumar.pandey@xyz.com7/18/2022 10:13:40 PM7/18/2022 10:45:19 PM
aditya.tiwari@xyz.com7/18/2022 10:13:46 PM7/18/2022 10:37:01 PM
gupta.sumit-s@xyz.com7/18/2022 10:13:07 PM7/18/2022 10:59:19 PM
sergio.jimenez-gaspar@xyz.com7/18/2022 9:55:25 PM7/18/2022 10:25:25 PM
pradeepkumar.pandey@xyz.com7/18/2022 9:50:35 PM7/18/2022 10:22:45 PM
aditya.tiwari@xyz.com7/18/2022 9:37:50 PM7/18/2022 10:27:25 PM
gupta.sumit-s@xyz.com7/18/2022 9:36:25 PM7/18/2022 10:05:06 PM

Hi @Abhishek8895 

 

Thank you for the sample data. I have applied it to the report. Let me know where you think the concurrent count is wrong. To me I think it is correct. 

vjingzhang_0-1659492564701.png

Best Regards,
Jing

Dear Jing,

 

Firstly, I really appreciate your help but it seems I am just getting crazy with this one..

I am using the same code as is with update on the table as mine is named as 'data' but the results I guess is wrong, attach screenshot where you can see it comes as 22,23 etc

 

I am doing everything exactly as it's in your PBIX but I cant get through. So I searched again..

 

I realised that the Agent connected on and Terminated On in my table is in a text format while in yours is date format, do you think - that could be the issue? If yes, how do I fix? As When I try to duplicate the tables and convert to table its gives error "Cannot parse...."

 

Your help will be appreciatedSnap.PNGSnap1.PNG

Hi @Abhishek8895 

 

Yes, it is probably the cause. Both the Agent connected on and Terminated On columns should be in Datetime data type. If it's in Text data type, the comparison with ">" and "<" operators will not work correctly to compare datetime values. 

 

You can change the data type at two places, one is in Power BI Desktop as below. 

vjingzhang_0-1659578333394.png

 

The other is in Power Query Editor as below. Then click Close&Apply or Apply to apply this change to Power BI Desktop. 

vjingzhang_1-1659578900663.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Yeah, I am aware of these two but as already mentioned, it wont allow me change the format from text to date/time and gives error. see attachedSnap.PNGSnap1.PNG

The sad part is, the database from where I am getting this data is coming in text format only.

 

Any other trick or solution you know, that could fix this?

Hi @Abhishek8895 Can you modify the data type in Power Query Editor? What will happen there?

Same thing, cannot parse..see attached

 

Reason is that this dataset is completely crazy, there is a "--" value in Agent terminated on date and that's why it doesnt allow to parse. Even I tried to due it DAX using datevalue..

 

Anything you could suggest?Snap1.PNGSnap2.PNGSnap3.PNG

Hi @Abhishek8895 

 

Oh I see. You need to clean data before changing the data type. What does "--" represent in the data table? If it represents blank datetime on that row, you can replace it with empty in the column. After changing its data type to datetime, it will display null without any error. Note that null datetime is a very small datetime in Power BI. If your "--" has other meanings, you need to replace it with another valid acceptable datetime value. 

vjingzhang_0-1659600486966.png

 

If "--" is meaningless in your data and you want to get rid of rows with "--", you can filter out rows that have "--". 

vjingzhang_1-1659601192455.png

 

After cleaning the data, you can change the data type correctly. 

 

Jing

 

 

 

 

If its ok with you, can we connect over call on teams or goggle meet and check this together..

My email is abhisheka013@gmail.com

Hi @Abhishek8895 

 

Sorry I cannot provide support outside of community. You can create a support ticket at https://powerbi.microsoft.com/support/ . It is free if you have a Pro license. The escalation engineer will contact you quickly via Email or Call to help solve it.

 

Best Regards,
Community Support Team _ Jing

No it doesnt fix as gets the same parse error message.

 

TheoC
Super User
Super User

Hi @Abhishek8895 

 

If the email that is presented in the screenshot is confidential, can you kindly remove it from the screenshot so it is not visible. 

 

Thank you in advance!


Theo 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Sorry, I did not understand what solution you are referring me to accept, as I didnt see anything..

 

Can you or anyone help please

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors