Forum Discussion
Running total with inactive relationship
I clearly have some way to go before I understand DAX, but I'm struggling to get a running total when using an inactive date relationship. This is my DAX:
Which works in that it gives me a running total, but what it doesn't do is stop at the max acquisition date - it returns the final total for all dates in the Date Table, which also means visuals exceed resources. This is my model, at least the part I'm using here:
Essentially the contact acquired table is a Factless Fact table used to store the date we acquired a contact. I've done some reading on expanded tables and theory behind DAX, but still can't wrap my head around it. Even Chat GPT has failed to give me a working DAX statement - any pointers greatly appreciated!
7 Replies
- amitchandak
Super User
jon_w , Try with these two measures
Measure 1= CALCULATE('_Measures'[Contact: Active Count],
USERELATIONSHIP('Contact Acquired'[Acquisition Date], 'Date Dimension'[Calendar Date]))zTest - Running Total 2 =
CALCULATE(
[Measure 1],
FILTER(
ALL('Date Dimension'),
'Date Dimension'[Calendar Date] <= MAX('Date Dimension'[Calendar Date])
&& 'Date Dimension'[Calendar Date] <= MAX('Contact Acquired'[Acquisition Date])
)
)- jon_wRegular Visitor
amitchandak thank you for the prompt response - but that still returns dates beyond the max acquisition date:
- AnonymousNot applicable
That's how cumulative totals work, as they are a sum of all the previous months, every month will have a cumulative value as long as one before it had one. If you want to remedy this you could do it in the measure like this:
IF(ISBLANK('_Measures'[Contact: Active Count]), BLANK(), /*The rest of that cumulative total measure*/)this isn't ideal because it will also return blanks within the date range where you may not want it to be blank. I'd suggest adding a column to your Date Dimension table:
Past/Present = IF('Date Dimension'[Calendar Date] <= NOW(), 1, 0)
You can then apply this filter to either the visual or within your measure and you will only see the total for dates that have happened. Hope this helps, let me know if you have any issues or further questions.