Forum Discussion
Start and end time
- 7 years ago
Hi jojo54
See if the following can fix it for what you need
Number of clients 2 = VAR vMinVal = MIN ( TimeTable[Value] ) VAR vMaxVal = MAX ( TimeTable[Value] ) VAR vNumberOfClients = COUNTROWS ( FILTER ( ALLSELECTED ( ClientsTbl ), ClientsTbl[Entry Time] <= vMinVal && ClientsTbl[Exit Time] >= vMaxVal ) ) RETURN vNumberOfClientsWhenever I have more time I could think of something better.
Hi jojo54
Here is an alternative using DAX
Number of clients =
VAR vMinVal =
MIN ( TimeTable[Value] )
VAR vMaxVal =
MAX ( TimeTable[Value] )
VAR vClientEntry =
CALCULATE (
COUNTROWS ( ClientsTbl ),
TimeTable[Value] <= vMinVal,
ALL ( TimeTable )
)
VAR vClientExit =
CALCULATE (
COUNTROWS ( ClientsTbl ),
TimeTable[Value] >= vMaxVal,
ALL ( TimeTable ),
USERELATIONSHIP ( ClientsTbl[Exit Time], TimeTable[Value] )
)
RETURN
MIN ( vClientExit, vClientEntry )Create a time table, then create a relationship between Start Time and the time value, and a second one between Exit Time and the time value. One will be an active relationship, while the second will be inactive.
Like this:
Then you can use that measure in your visualization. Time value in X axis and the measure in the Value area
And you can also make use of the same DAX code in the data model of Excel (Power Pivot)
Let us know what works for you
- jojo547 years agoFrequent Visitor
Thanks for this solution! I like that I can actually write this down to work out what it's doing!
But I'm finding an issue with the below: (updated table)
Name Entry Time Exit Time Person 1 6:00 9:00 Person 2 7:00 8:30 Person 3 8:15 9:15 Person 4 6:45 10:00 Person 5 7:15 7:45 If I were to look at 8am, according to the DAX query,
vcliententry = 4
vclientexit = 4
So query will return 4 being min (4,4)
However there's actually only 3 people who's at the cafe (Person 1,2,4)
I tried writing this on paper and I've worked out that this mis-calculation occurs when there are people on the list who have exited prior to the TimeValue AND there are people who not yet entered into the cafe at the TimeValue.
Any ideas on how to fix this?
Thanks!
- Geradav7 years ago
Responsive Resident
Hi jojo54
See if the following can fix it for what you need
Number of clients 2 = VAR vMinVal = MIN ( TimeTable[Value] ) VAR vMaxVal = MAX ( TimeTable[Value] ) VAR vNumberOfClients = COUNTROWS ( FILTER ( ALLSELECTED ( ClientsTbl ), ClientsTbl[Entry Time] <= vMinVal && ClientsTbl[Exit Time] >= vMaxVal ) ) RETURN vNumberOfClientsWhenever I have more time I could think of something better.