Forum Discussion
Working with multiple date keys in table
- 4 years ago
In DAX you can use the same approach.
Measure = AVERAGEX('DWH DIM_CLAIM', DATEVALUE(Left([CloseDateKey],4) & "-" & MID([CloseDateKey],5,2) & "-" & RIGHT([CloseDateKey],2)) -DATEVALUE(Left([CreateDateKey],4) & "-" & MID([CreateDateKey],5,2) & "-" & RIGHT([CreateDateKey],2)))
lbendlin ,
That works perfectly fine! Datevalue was a function i did not know about.
One more thing is that there is a reason that Calendar table exists.
Is there an approach, where we can use the Calendar table in order to actually work on relationships/Keys. It is just due to some CloseDateKey's that are not date yet (-1 key is a blank value in calendar table, meaning something did not Finish/Close yet). What do you think?
If it does not sound possible/reasonable i will accept ur solution above.
I believe that I could also make a condition with ur latest measure to avoid counting if CloseDateKey is -1, but for some learning purposes i'd like to know if there is a way to perform this using keys/relationships as mentioned paragraph above.
This is going into outer join and USERELATIONSHIP territory. Without good sample data ( and a bit more context on what you are trying to achieve and what the expected result should look like ) it will be difficult to help more.
- Anonymous4 years agoNot applicable
Sure
- lbendlin4 years agoSuper User
1. Find Date in Calendar table by DateKey for CreateDateKey and CloseDateKey.It's either or. You can't have both dates linked with the calendar table in an active relationship. One of them has to be inactive.
- Anonymous4 years agoNot applicable
Aight, so userelationship won't solve this. thanks
- grantsamborn4 years agoSolution Sage
What about 2 date tables? CreatedDate and ClosedDate
Regarding records with no closed date: Would it help to use PowerQuery to replace nulls with the Datekey for the CURRENT DATE?
If so, consider trying this.
pbix: https://1drv.ms/u/s!AnF6rI36HAVkhPFMNE3v3SoIIN_0AQ?e=vygzJ2
Apologies: I could have used MUCH simpler date tables but I usually get lazy and use an M script I have. Your date table should work.
- Anonymous4 years agoNot applicable
Thats completly fine. But i got my take more clearly now.
My idea is to relate two datekeys with calendar table within measure. You could imagine this by let's say that datekeys would be smh like NOT 20220813 is a 8/13/2022 but lets say key 1 would be 8/13/2022 key 2 8/14/2022 etc.
But yeah, in my scenario datekys are 'transformable' into date so it aint a problem.
Thanks for help guys!