Forum Discussion
Function Related doesn't seem to work
isjoycewang i'm still working on this formula but I just can't seem to get the data out of the Date table into my Tickets Table.
But I can get stuf out of my IncidentsTable but that means I go through the Date Table so what does that mean ?
There has to be something wrong with the relationship but i'm not sure what.
A part of the formula gets data from the date table (for example, it does return a value based on DatesBetween) so full days it can calculate.
Doorlooptijd =
VAR ServiceWindowStart = Calculate(SELECTEDVALUE(ServiceWindow[ServiceWindow]),ServiceWindow[Dag]="Start")
VAR ServiceWindowEind = Calculate(SELECTEDVALUE(ServiceWindow[ServiceWindow]),ServiceWindow[Dag]="Eind")
VAR ServiceWindowPerDag = VALUE(ServiceWindowEind-ServiceWindowStart)*24
VAR DezeStartTijd = Tickets[StartTijd]
VAR DezeEindTijd = Tickets[EindTijd]
VAR StartDatum =Tickets[StartDate]
VAR EindDatum = Tickets[EndDate]
VAR EersteDagVerstrekenTijd = Switch(TRUE(),
Related('Date'[ServiceWindow])=0,0,
DezeStartTijd>=ServiceWindowEind,0,
DezeStartTijd<=ServiceWindowStart,ServiceWindowPerDag,
StartDatum = EindDatum && DezeEindTijd < ServiceWindowEind,Round((DezeEindTijd-DezeStartTijd)*24,3),
ROUND((ServiceWindowEind-DezeStartTijd)*24,3))
VAR LaatsteDagVerstrekenTijd = Switch(TRUE(),
LOOKUPVALUE('Date'[ServiceWindow],'Date'[Date],EindDatum)=0,0,
DezeEindTijd<=ServiceWindowStart,0,
DezeEindTijd>=ServiceWindowEind,ServiceWindowPerDag,
StartDatum = EindDatum ,0,
ROUND((DezeEindTijd-ServiceWindowStart)*24,3))
VAR VolledigeWerkdagen = Calculate (sum('Date'[ServiceWindow]),DATESBETWEEN('Date'[Date],StartDatum+1,EindDatum-1))
VAR TotaalAantalUren = EersteDagVerstrekenTijd+VolledigeWerkdagen*ServiceWindowPerDag+LaatsteDagVerstrekenTijd
Return TotaalAantalUren
The formula part(s) that don't work are the VAR EersteDagVerstrekenTijd en VAR LaatsteDagVerstrekenTijd and I don't know why ?
Here you can see the results of the formula if I break them down, you can see that the VAR EersteDagVerstrekenTijd /LaatsteDagVerstrekenTijd don't work and the last part does
amitchandak or lbendlin maybe you know the solution ?
RELATED should not be used in measures, only in calculated columns.
- lbendlin2 years agoSuper User
Any chance of getting meaningful sample data and an indication of the expected results?
- lbendlin2 years agoSuper User
Thanks. Does it need to be DAX or is Power Query ok too?
- lbendlin2 years agoSuper User
The date table has nothing to do with your scenario. You need a Minutes table, but my last version removed that requirement too.
- lbendlin2 years agoSuper User
As I said before, a MinuteCalendar is not required any more. Only the intervals are considered (cardinality reduction), so that will be faster. But you can try materializing that table. There's no good reason to recreate it for every row (other than that the code looks slicker).
- RonaldvdH2 years agoPost Patron
lbendlin the sample data was in the picture basically it's a couple of columns with a startdate/time and an enddate/time and then calculate the number of business hours between the two dates
For example:
WMS_ID StartDate StartDateTime EndDate EndDateTime BusinessHours WMS000512325 maandag 14 november 2022 14:22:00 donderdag 17 november 2022 16:20:00 WMS000512326 maandag 14 november 2022 15:33:00 donderdag 17 november 2022 20:54:00 WMS000512327 maandag 14 november 2022 19:00:00 woensdag 16 november 2022 16:15:00 WMS000512328 dinsdag 15 november 2022 14:22:00 donderdag 17 november 2022 12:04:00 Business Hours are:
Monday till Friday 08:00 - 20:00Saterday 08:00 - 12:00
- lbendlin2 years agoSuper User
see attached. Can be further simplified if you want to avoid creating the MinuteCalendar table. There will be a performance penalty for large date ranges.
- RonaldvdH2 years agoPost Patron
lbendlin in your formula there is a part : GeneratesSeries(0,1439)
However seeing that my data has 2 years worth of dates and if I make a MinuteCalendar that table would have 1.051.200 rows I don't think that does wonders for the performance right ?
Ive already tried change the value tot a 1.051.200 but my laptop is still busy .... hhaha