Forum Discussion

Big_Trucks's avatar
Big_Trucks
Frequent Visitor
5 years ago
Solved

Conditional filter by importance

Hi All, I have looked extensively for help on this item and have been unable to find something similar. What I want to do is be able to sort out from a table a specific set of rows according to...
  • stevedep's avatar
    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.