Forum Discussion
Sum Dollar value between 2 dates
- 9 years ago
Hi, I made a simple example with your data and a calculated table In this file.
Have fun with DAX!
Alberto Ferrari
http://www.sqlbi.com
Hi malcolms,
When you select Area, there is no impact on the chart. That is because when you create a calculated column Date[Dollar], you get all areas dollars. And the calculated column would not be changed by slicer, you can review this knowledage base for more details.
So for your requirement, you need to get different area's dollars. I create the following sample table named 'Test'.
Then create a date table using the formula.
Date = CALENDAR(MIN(Test[Start Date]),MAX(Test[End Date]))
In the Date table, create calculated column using the formulas.
AA-Dollar = CALCULATE(SUM(Test[Dollar]),
FILTER(Test,
Test[Start Date]<='Date'[Date]&&Test[End Date]>='Date'[Date]&&Test[Area]="AA"
)
)
BB-Dollar = CALCULATE(SUM(Test[Dollar]),
FILTER(Test,
Test[Start Date]<='Date'[Date]&&Test[End Date]>='Date'[Date]&&Test[Area]="BB"
)
)
CC-Dollar = CALCULATE(SUM(Test[Dollar]),
FILTER(Test,
Test[Start Date]<='Date'[Date]&&Test[End Date]>='Date'[Date]&&Test[Area]="CC"
)
)
DD-Dollar = CALCULATE(SUM(Test[Dollar]),
FILTER(Test,
Test[Start Date]<='Date'[Date]&&Test[End Date]>='Date'[Date]&&Test[Area]="DD"
)
)
Please note, I think we should use the sum function(in bold) rather than max in the post. For example, the dollar from 2017/4/1 to 2017/4/10 is 10, another record dollar 2017/4/5 to 2017/4/10 is 20, the total dollar should be (10+20) during 2017/4/5-2017/4/10, rather than the max value 20.
Finally, you need to create a measure to get the corresponding total dollar based on the selected area value.
Total-dollar = SWITCH(SELECTEDVALUE(Test[Area]),
"AA",SUM('Date'[AA-Dollar]),
"BB",SUM('Date'[BB-Dollar]),
"CC",SUM('Date'[CC-Dollar]),
"DD",SUM('Date'[DD-Dollar])
)
Create a chart, select the data as x-axis, the measure as value, then you select different in slicer, there is impact on the chart. Please see the screenshot, and you can download the attachment to test.
Select Area "AA"Select Area "CC"
Best Regards,
Angelia