March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi,
I want to calculate the session duration per user per day. In the table below, we have different users with different sessions date.
User | Number of sessions | Session date | Session Duration |
A | 1 | 28/07/2021 10 AM | 100 |
B | 3 | 29/07/2021 11 AM | 130 |
B | 3 | 29/07/2021 12 PM | 200 |
B | 3 | 30/07/2021 13 PM | 250 |
C | 4 | 12/08/2021 10 AM | 40 |
C | 4 | 12/08/2021 11 AM | 30 |
C | 4 | 12/08 2021 13 PM | 120 |
C | 4 | 13/08/2021 14 PM | 140 |
I am looking for a calculated column to sum the sessions per user per day. The answer should look like this:
User | Sum |
A | 100 |
B | 330 |
B | 330 |
B | 250 |
C | 190 |
C | 190 |
C | 190 |
C | 140 |
You can see that for example, for user B, the first two rows are 330. It's because they happened on the same day.
Thanks.
Hi @ArashZ Jan,
Try this code to add a new column:
Sum =
CALCULATE (
SUM ( 'Table'[Session Duration] ),
ALLEXCEPT ( 'Table', 'Table'[User], 'Table'[Session date] )
)
Output:
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos✌️!!
@ArashZ Try:
Column =
VAR __User = [User]
VAR __Date = [Session date]
RETURN
SUMX(FILTER('Table',[User]=__User && [Session date] = __Date),[Session Duration])
@ArashZ Ah, I missed there were different times on same day. Try:
Column =
VAR __User = [User]
VAR __Date = TRUNC([Session date])
RETURN
SUMX(FILTER('Table',[User]=__User && TRUNC([Session date]) = __Date),[Session Duration])
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
25 | |
18 | |
15 | |
9 | |
8 |
User | Count |
---|---|
37 | |
32 | |
18 | |
16 | |
13 |