Forum Discussion
Filter using last date not working
- 6 years ago
I fixed this. Here is the DAX.
Last Sale Amount2 = CALCULATE(sum(Table1[Sales]), All('Date'[Quarter]), CALCULATETABLE(LASTDATE(Table1[Date]),ALLEXCEPT(Table1, 'Table1'[Customer Name]) ))
Hi gunjan80 ,
Sorry for that if a relationship is established, only quarters with data will be displayed.
Maybe you can create a new date table and create a relationship with original table to do some calculations.
Or you can create four Measures to calculate quarter sales separately.
Q1 =
VAR _maxQ =
CALCULATE (
MAX ( Table1[Quarter] ),
FILTER (
ALLSELECTED ( Table1 ),
Table1[Customer Name] = MAX ( Table1[Customer Name] )
)
)
RETURN
IF (
"Q1" <= _maxQ,
CALCULATE ( SUM ( Table1[Sales] ), FILTER ( Table1, Table1[Quarter] = "Q1" ) ),
CALCULATE ( SUM ( Table1[Sales] ), FILTER ( Table1, Table1[Quarter] = _maxQ ) )
)
Q2 =
VAR _maxQ =
CALCULATE (
MAX ( Table1[Quarter] ),
FILTER (
ALLSELECTED ( Table1 ),
Table1[Customer Name] = MAX ( Table1[Customer Name] )
)
)
RETURN
IF (
"Q2" <= _maxQ,
CALCULATE ( SUM ( Table1[Sales] ), FILTER ( Table1, Table1[Quarter] = "Q2" ) ),
CALCULATE ( SUM ( Table1[Sales] ), FILTER ( Table1, Table1[Quarter] = _maxQ ) )
)
Q3 =
VAR _maxQ =
CALCULATE (
MAX ( Table1[Quarter] ),
FILTER (
ALLSELECTED ( Table1 ),
Table1[Customer Name] = MAX ( Table1[Customer Name] )
)
)
RETURN
IF (
"Q3" <= _maxQ,
CALCULATE ( SUM ( Table1[Sales] ), FILTER ( Table1, Table1[Quarter] = "Q3" ) ),
CALCULATE ( SUM ( Table1[Sales] ), FILTER ( Table1, Table1[Quarter] = _maxQ ) )
)
Q4 =
VAR _maxQ =
CALCULATE (
MAX ( Table1[Quarter] ),
FILTER (
ALLSELECTED ( Table1 ),
Table1[Customer Name] = MAX ( Table1[Customer Name] )
)
)
RETURN
IF (
"Q4" <= _maxQ,
CALCULATE ( SUM ( Table1[Sales] ), FILTER ( Table1, Table1[Quarter] = "Q4" ) ),
CALCULATE ( SUM ( Table1[Sales] ), FILTER ( Table1, Table1[Quarter] = _maxQ ) )
)
If you have any question, please kindly ask here and we will try to resolve it.
Best regards,
Community Support Team _ zhenbw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
BTW, pbix as attached.
I fixed this. Here is the DAX.
- v-zhenbw-msft6 years agoCommunity Support
Hi gunjan80 ,
Glad you found the solution.
Please mark your reply as an answer, let more people find it more quickly, thanks.
Best regards,
Community Support Team _ zhenbw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- gunjan806 years agoMicrosoft Employee
I've marked it as a solution. Thankyou for helping me on this.