Forum Discussion
How to work Running Total with VALUES
- 1 year ago
hi lbendlin ,
I only partly followed your suggestion for Running Total of the differences in days between the current share date and the initial, first share date. I used the DATEDIFF function after setting a ‘First Share Date’ and a ‘Current ShareDate’.
Similarly, I set a ‘First Share Value’ and a ‘Last Share Value’. The difference between the two values gives me the Running Total in the filter context.
In other words, I kept the double relationship of the two date columns in the fact table with the Calendar Table, but I followed your suggestion of calculating the days as the difference between the two dates.
This is fine for now.
Below is a picture of the resultThank you
Hi gennaro_19 ,
Thank you for your feedback. The issue in the original running total measure is that VALUES('DataBase'[Date Share Value]) was used without properly filtering it to include only dates less than or equal to the current row context. This causes the measure to evaluate only for a single date—specifically the last one in the model—while all other rows return blank. To correct this, the virtual table inside SUMX needs to be filtered appropriately. The corrected version uses MAX('DataBase'[Date Share Value]) to capture the current row’s date in a matrix visual and applies this as a filter condition to the set of distinct valuation dates. Here's the corrected version of the measure for share value differences:
RT_Diff_Share_Value_Corrected :=
VAR CurrentDate = MAX('DataBase'[Date Share Value])
RETURN
CALCULATE(
SUMX(
FILTER(
VALUES('DataBase'[Date Share Value]),
'DataBase'[Date Share Value] <= CurrentDate
),
[Diff Share Value]
)
)
And the equivalent measure for cumulative days difference is:
RT_Diff_Days_Corrected :=
VAR CurrentDate = MAX('DataBase'[Date Share Value])
RETURN
CALCULATE(
SUMX(
FILTER(
VALUES('DataBase'[Date Share Value]),
'DataBase'[Date Share Value] <= CurrentDate
),
[Diff Days]
)
)
These measures ensure that the accumulation includes only distinct valuation dates up to and including the current one, allowing the running total to increment row by row in the matrix as expected.
Best regards,
Hi DataNinja777 ,
Thank you again for the help you are providing.
I have supplemented your measures with the activation of the second relationship between the calendar dates and the dates of the odds valuation.
But as you can see the proposed measures still do not work, still do not return a Running Total and I am reliving the same frustrations of my many attempts before asking the Community for help.
I am a DAX neophyte and I am trying to learn and improve my knowledge by insisting on finding solutions to the path I have set for myself.
I believe that the proposed measures do not work because they lack a function that changes the filter context as ALL.
But, as I said in the initial post, if we add ALL, we also bring in the dates of double payments in the month.
Quite a dilemma.
Here is the link to the file
https://drive.google.com/file/d/1Aw73Thv-iMAdaSAX5p0ipnMw5BFUcVbL/view?usp=drive_link
I have made it free to access and edit the.pbix file, please try the solution directly in the file.
Best regards