Forum Discussion
Conditional filter by importance
- 5 years ago
Hi,
This was a nice one! Please see below how it works. You can select a date, which is used to define the time frame of 6 months. It will then look for accepted quotes, if it does not find any (coalece), it will take the most recent declined quote. Enjoy!
Please note; the date table is unrelated!The DAX code:
_Filter = VAR _selCurrentDate = SELECTEDVALUE ( DateDim[Date] ) VAR _6monthprior = EDATE ( _selCurrentDate, -6 ) RETURN IF ( NOT ( ISBLANK ( SUM ( 'Table'[AMOUNT $] ) ) ), COALESCE ( CALCULATE ( COUNT ( 'Table'[ACCEPTED/DECLINED] ), FILTER ( 'Table', [DATE].[Date] > _6monthprior && [DATE].[Date] <= _selCurrentDate && [ACCEPTED/DECLINED] = "ACCEPTED" ) ), VAR _SELcar = SELECTEDVALUE ( 'Table'[Car Number] ) VAR _MaxDateDeclined = CALCULATE ( MAX ( 'Table'[DATE].[Date] ), FILTER ( ALL ( 'Table' ), [Car Number] = _SELcar && [DATE].[Date] > _6monthprior && [DATE].[Date] <= _selCurrentDate && [ACCEPTED/DECLINED] = "DECLINED" ) ) RETURN CALCULATE ( COUNT ( 'Table'[ACCEPTED/DECLINED] ), FILTER ( 'Table', [DATE].[Date] = _MaxDateDeclined && [Car Number] = _SELcar ) ) ), BLANK () )File is attached.
Kind regards, Steve.
Hi,
This was a nice one! Please see below how it works. You can select a date, which is used to define the time frame of 6 months. It will then look for accepted quotes, if it does not find any (coalece), it will take the most recent declined quote. Enjoy!
Please note; the date table is unrelated!
The DAX code:
_Filter =
VAR _selCurrentDate =
SELECTEDVALUE ( DateDim[Date] )
VAR _6monthprior =
EDATE ( _selCurrentDate, -6 )
RETURN
IF (
NOT ( ISBLANK ( SUM ( 'Table'[AMOUNT $] ) ) ),
COALESCE (
CALCULATE (
COUNT ( 'Table'[ACCEPTED/DECLINED] ),
FILTER (
'Table',
[DATE].[Date] > _6monthprior
&& [DATE].[Date] <= _selCurrentDate
&& [ACCEPTED/DECLINED] = "ACCEPTED"
)
),
VAR _SELcar =
SELECTEDVALUE ( 'Table'[Car Number] )
VAR _MaxDateDeclined =
CALCULATE (
MAX ( 'Table'[DATE].[Date] ),
FILTER (
ALL ( 'Table' ),
[Car Number] = _SELcar
&& [DATE].[Date] > _6monthprior
&& [DATE].[Date] <= _selCurrentDate
&& [ACCEPTED/DECLINED] = "DECLINED"
)
)
RETURN
CALCULATE (
COUNT ( 'Table'[ACCEPTED/DECLINED] ),
FILTER ( 'Table', [DATE].[Date] = _MaxDateDeclined && [Car Number] = _SELcar )
)
),
BLANK ()
)
File is attached.
Kind regards, Steve.
stevedepThank you so much for the help. You are directionally where I need to be headed. I think slight tweaks will to your outline will work for me. I hadn’t even thought to break it down with date VARs. That really helped to go line by line as needed. I know it was a bit of a complex problem, but you nailed it. Thanks again.
- stevedep5 years agoMemorable Member
Welcome! I enjoy the complex problems the most 🙂