This is a simple calculation of Date Difference, yet the scenario itself is complex.
Scenario: I have 3 tables, one fact and two dimensions. Below please find the tables with sample data:
Fact Table
ProductSK DateSK
ABC 01/01/2011
XYZ 01/02/2011
DEF 09/09/2010
Product Dimension Table
ProductSK PKPN
ABC RTY
ABC UOP
XYZ WER
XYZ WQS
DEF NMB
DEF SDF
DATE Dimension is a regular calendar date dimension as in your book.
Few words about the Scenario: The fact table relates to products dimension via ProductSK. The fact table relates to DATE dimension via Datesk. There is no relationship between Product Dimension and Date Dimension. What I am seeking here is to get date difference between first date of each pkpn to todays date. For Example, For PKPN “RTY” the first date is 01/01/2011, then the date difference is TODAY() or NOW() minus the first date (which would be 01/01/2011). Also, I need to mention that for each ProductSK there will be Many PKPNs and the combination of ProductSK and PKPN will give us the correct dates.
Solution: I tried Many solutions but to no satisfaction. I think I am doing almost right but, I am not getting the exact answers. Javier Guillen provided me with this wonderful example of LOOKUPVALUE function in DAX in order to get minimum date. Also with the Alberto example, Counting Active Days (
sqlblog.com/blogs/alberto_ferrari/archiv...ing-active-days.aspx) I was able to get some of the information but not correct one. I have been working on this for couple of days but I don’t see the soil yet. Any help is appreciated . Below is the solution I arrived yet.
=SUMX (
‘FactTable’,
CALCULATE (
COUNTROWS (Date),
Date[Date] >= EARLIER (LOOKUPVALUE(DATE(DATE),DATE(DATESK),MIN(FACTTABE[DATE]))),
Date[Date] <= TODAY()
)
)
Thanks