The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
Hi guys,
I have a table with userID wich identifies the user, date which identifies the day, Action which can be a list of things, time which records the time the action was done .
What i need to do is calculate the datediff in seconds between two actions (so between the current row and the next) and I need to do it gruping by userID and date, so that in the end I can sum this results and obtain the total time "worked" (I define time worked as the time spans between two rows) for each user in each day. I think I should use VARs to identify the rows and Allexcept to create the subgroup but I'm stuck
Thanks for your help
So just so that I understand your problem correctly:
As far as the measure used to get this, it depends on how you plan to display it. If it's in a tabular visual like a matrix, with date and userID as the rows, then the matrix visual is doing your grouping already. If you're trying to display it in a card, it will need a slightly tweaked formula, since the grouping isn't done automatically. Let us know how you intend to display/use this measure, and we can help more specifically.
This should get you started, and would be the general form, assuming you have another mechanism to filter down to one User/Date combo (the visual itself, a set of slicers, page filters, etc):
Hours Worked =
SUMX(
Table1[timestamp],
DATEDIFF(
CALCULATE(
MAX(Table1[timestamp]),
FILTER(ALLEXCEPT(Table1, Table1[userID], Table1[date]), Table1[timestamp]<SELECTEDVALUE(Table1[timestamp]))
),
Table1[timestamp],
SECOND
)
)
User | Count |
---|---|
71 | |
64 | |
62 | |
50 | |
28 |
User | Count |
---|---|
117 | |
75 | |
62 | |
55 | |
43 |