Forum Discussion
Earliest Date Calculations
- 6 years ago
Hi Anonymous
Sure,
CALCULATED modifies Filter Context
TREATAS applies context on Table Date and filters it to only __minDate ValueKEEPFILTERS ensures the value is not calculated for 01/06/2019 as no new contracts there.
You could simplify this syntax and remove TREATAS like below
VAR __minDate = CALCULATE( MIN( 'Table'[Date] ), ALL( 'Table' ), VALUES( 'Table'[Customer/Contract] ) ) RETURN CALCULATE( COUNTROWS( 'Table' ), KEEPFILTERS( 'Table'[Date] = __minDate ) ) + 0Learn more about
TREATAS - https://www.sqlbi.com/blog/marco/2017/11/25/using-treatas-in-place-of-in-in-dax/
KEEPFILTERS - https://www.sqlbi.com/articles/using-keepfilters-in-dax/
Best Regards,
Mariusz
If this post helps, then please consider Accepting it as the solution.
Hi Anonymous
Try this
Measure =
VAR __minDate =
CALCULATE(
MIN( 'Table'[Date] ),
ALL( 'Table' ),
VALUES( 'Table'[Customer/Contract] )
)
RETURN
CALCULATE(
COUNTROWS( 'Table' ),
KEEPFILTERS( TREATAS( { __minDate }, 'Table'[Date] ) )
) + 0
Mariusz
If this post helps, then please consider Accepting it as the solution.
- Anonymous6 years agoNot applicable
Mariusz Thanks for your quick reply, Could you please explain little bit in details how we are calcualting this measure, especially this part of the formula, I am quite new in DAX and trying to understand what does this part of DAX is:
CALCULATE(
COUNTROWS( 'Table' ),
KEEPFILTERS( TREATAS( { __minDate }, 'Table'[Date] ) )
) + 0- Mariusz6 years ago
Community Champion
Hi Anonymous
Sure,
CALCULATED modifies Filter Context
TREATAS applies context on Table Date and filters it to only __minDate ValueKEEPFILTERS ensures the value is not calculated for 01/06/2019 as no new contracts there.
You could simplify this syntax and remove TREATAS like below
VAR __minDate = CALCULATE( MIN( 'Table'[Date] ), ALL( 'Table' ), VALUES( 'Table'[Customer/Contract] ) ) RETURN CALCULATE( COUNTROWS( 'Table' ), KEEPFILTERS( 'Table'[Date] = __minDate ) ) + 0Learn more about
TREATAS - https://www.sqlbi.com/blog/marco/2017/11/25/using-treatas-in-place-of-in-in-dax/
KEEPFILTERS - https://www.sqlbi.com/articles/using-keepfilters-in-dax/
Best Regards,
Mariusz
If this post helps, then please consider Accepting it as the solution.- Anonymous6 years agoNot applicable
MariuszThanks a lot for your extended help. I appreciate your prompt reply and taking out time to answer it.