Forum Discussion
Cumulative Totals Including Non-Filtered Values
Hi Everyone! So close to having this figured out!
See the screenshot below.
Here are the formulas that I have:
novotnajk
Use ALLSELECTED.$ Cumulative Medical Spend = VAR _CurrentDate = MAX ( 'Reporting'[reporting_date] ) VAR _Calc = CALCULATE ( [$ Medical Spend], FILTER ( ALLSELECTED ('Reporting'), 'Reporting'[reporting_date] <= _CurrentDate ) ) RETURN _Calc$ Cumulative SL Medical Spend = VAR _CurrentDate = MAX ( 'Reporting'[reporting_date] ) VAR _Calc = CALCULATE ( [$ SL Medical Spend], FILTER ( ALLSELECTED ( 'Reporting' ), 'Reporting'[reporting_date] <= _CurrentDate ) ) RETURN _CalcHi novotnajk
Here you go.Running Total = var _minDateCalc = CALCULATE(MIN(MedicalSpend[Reporting Date]),ALLSELECTED()) // This uses ALLSELECTED() and thus gets the minimum date based on the slicer VAR _beginningDate = MIN ( MedicalSpend[Reporting Date] ) VAR _currentDate = MAX ( MedicalSpend[Reporting Date] ) Var _specialID = MAX(MedicalSpend[Special ID]) VAR _calc = CALCULATE ( [Sum of Medical Spend], ALL(MedicalSpend), MedicalSpend[Reporting Date] <= _currentDate && MedicalSpend[Reporting Date]>= _minDateCalc, MedicalSpend[Special ID]=_specialID ) RETURN _calc+0
It was the beginning date that was the problem. The minimum date that was pulling before, was the minimum date on each row, which is why it did not total. The new var calculates the minimum date from the table based on the slicer because we use ALLSELECTED() and calculate it before we do the main calculation.
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel
5 Replies
- FowmySuper User
novotnajk
Use ALLSELECTED.$ Cumulative Medical Spend = VAR _CurrentDate = MAX ( 'Reporting'[reporting_date] ) VAR _Calc = CALCULATE ( [$ Medical Spend], FILTER ( ALLSELECTED ('Reporting'), 'Reporting'[reporting_date] <= _CurrentDate ) ) RETURN _Calc$ Cumulative SL Medical Spend = VAR _CurrentDate = MAX ( 'Reporting'[reporting_date] ) VAR _Calc = CALCULATE ( [$ SL Medical Spend], FILTER ( ALLSELECTED ( 'Reporting' ), 'Reporting'[reporting_date] <= _CurrentDate ) ) RETURN _Calc- novotnajkResolver I
That didn't work. The values stayed the same. 😞
Should I change anything to the underlying measures within each?
$ Medical Spend = CALCULATE(SUM(Medical[cost]))$ SL Medical Spend =CALCULATE (SUMX (FILTER (SUMMARIZE ( Medical, Medical[special_id], "Aggregate", [$ Medical Spend] ),[Aggregate] >= [$ SL]),[Aggregate]))+0
- Nathaniel_CCommunity Champion
Hi novotnajk
Here you go.Running Total = var _minDateCalc = CALCULATE(MIN(MedicalSpend[Reporting Date]),ALLSELECTED()) // This uses ALLSELECTED() and thus gets the minimum date based on the slicer VAR _beginningDate = MIN ( MedicalSpend[Reporting Date] ) VAR _currentDate = MAX ( MedicalSpend[Reporting Date] ) Var _specialID = MAX(MedicalSpend[Special ID]) VAR _calc = CALCULATE ( [Sum of Medical Spend], ALL(MedicalSpend), MedicalSpend[Reporting Date] <= _currentDate && MedicalSpend[Reporting Date]>= _minDateCalc, MedicalSpend[Special ID]=_specialID ) RETURN _calc+0
It was the beginning date that was the problem. The minimum date that was pulling before, was the minimum date on each row, which is why it did not total. The new var calculates the minimum date from the table based on the slicer because we use ALLSELECTED() and calculate it before we do the main calculation.
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel