Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Dear experts,
I have a table like the example below with product ID, StartDate, EndDate. I would like to calculate the difference between the last EndDate and the first StartDate per each iem ID, like shown in the DateDiff column. Is that possible with a measure? Appreciate if you can offer some help.
TIA!
ID | StartDate | EndDate | DateDiff |
1 | 21-12-11 22:30 | 21-12-11 23:47 | 0.04167 |
1 | 21-12-11 23:47 | 21-12-11 23:30 | 0.04167 |
2 | 21-12-11 23:57 | 22-12-11 0:00 | 0.01250 |
2 | 22-12-11 0:00 | 22-12-11 0:14 | 0.01250 |
2 | 22-12-11 0:14 | 22-12-11 0:15 | 0.01250 |
3 | 22-12-11 0:27 | 22-12-11 0:40 | 0.02569 |
3 | 22-12-11 0:40 | 22-12-11 0:55 | 0.02569 |
3 | 22-12-11 0:55 | 22-12-11 1:04 | 0.02569 |
4 | 22-12-11 1:06 | 22-12-11 1:57 | 0.04514 |
4 | 22-12-11 1:57 | 22-12-11 2:03 | 0.04514 |
4 | 22-12-11 2:03 | 22-12-11 2:11 | 0.04514 |
Solved! Go to Solution.
Please try this column expression and convert the column to type decimal.
NewColumn =
VAR thisID = IDs[ID]
VAR minDT =
MINX ( FILTER ( IDs, IDs[ID] = thisID ), IDs[StartDate] )
VAR maxDT =
MAXX ( FILTER ( IDs, IDs[ID] = thisID ), IDs[EndDate] )
RETURN
maxDT - minDT
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
Please try this column expression and convert the column to type decimal.
NewColumn =
VAR thisID = IDs[ID]
VAR minDT =
MINX ( FILTER ( IDs, IDs[ID] = thisID ), IDs[StartDate] )
VAR maxDT =
MAXX ( FILTER ( IDs, IDs[ID] = thisID ), IDs[EndDate] )
RETURN
maxDT - minDT
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
Are you sure you want a measure and not a calculated column? What should a measure return if there are many different ID's visible in the current context? Your picture suggests that you want a calculated column...
@Anonymous you are right, a calculated column will work better for my case. I am not really familiar though, could you help me through the steps please? Thank you
User | Count |
---|---|
17 | |
14 | |
13 | |
13 | |
11 |
User | Count |
---|---|
19 | |
15 | |
15 | |
11 | |
10 |