Forum Discussion

BK1234's avatar
BK1234
Helper I
6 years ago
Solved

Filter attribute in list

Hello,   Whatever I try, I can't seem to get the following working.   I have a fact-table with all kinds of measures for orders. See this example: Order   OrderClosedDate    DatePayment    Price...
  • speedramps's avatar
    6 years ago

    Hi BK

     

    Please consider this solution

     

    The problem

    ========

    You have a order header table with a status flag = open or closed.

    You have a order line table with has a many:1 relationship with the order header table.

    The order line table has a closed date and payment date column..

    Your requirement is to have 2 slicers with payment date and order status with  closed, open or both.

    • If status slicer = closed than show all orders that have a closed date <= payment date slicer
    • If status slicer = open than show all orders that have a closed date = blank or closed date   > payment date slicer
    • If status slicer = both than show all orders

     

    The solution

    =======

    1) Add your tables

     

    OrderHeader

    OrderID

    OrderChannel

    OrderStatus

    1

    Phone

    Open

    2

    Web

    Closed

    3

    Mail Order

    Open

    4

    Over counter

    Closed

    5

    Phone

    Open

    6

    Web

    Closed

    7

    Mail Order

    Open

    8

    Over counter

    Closed

    9

    Web

    Open

     

    OrderLine

    OrderIDClosedDatPaymentDateQty
    101/01/202001/02/202010
    201/02/202001/01/202020
    3 01/01/202030
    401/01/202001/02/202040
    401/01/202001/02/202050
    4 01/01/202060
    501/03/2020 70
    5 01/03/202080
    601/03/202001/04/202090
    601/03/202001/04/2020100
    601/01/202001/04/2020110
    7 01/05/2020120
    801/05/2020 130
    901/05/202001/05/2020140

     

    ListOfOptions

    OptionID

    OptionName

    1

    Closed not paid

    2

    Open not paid

    3

    Both

     

    Calendar

    Date

    01/01/2019

    etc, etc

    31/12/2020

     

     

    2) Add relationships

    Add a 1:M relationship between OrderHeader and OrderLine.

    But leave the Calendar table disconnected.

     

    3) Add date slicer

    Drag the Calendar date to a single drop down slicer (dont use a date range)

     

    4) Add DAX measures:-

     

    Total qty = SUM(OrderLine[Qty])

     

    Closed not paid =

    CALCULATE([Total qty],OrderHeader[OrderStatus]="Closed",

    FILTER(OrderLine,OrderLine[ClosedDate]< MIN('Calendar'[Date])))

     

    Open not paid =

    CALCULATE([Total qty],OrderHeader[OrderStatus]="Open",

    FILTER(OrderLine,OrderLine[ClosedDate] = BLANK() ||

    OrderLine[ClosedDate] > MIN('Calendar'[Date])))

     

    Selected qty =

    SWITCH(

        SELECTEDVALUE(ListOfOptions[OptionID]),

        1,[Closed not paid],

        2,[Open not paid],

        3,[Total qty],

        BLANK()

     

    5) Add a table visual with

    OrderHeader[OrderId]

    Selected qty

     

    6) Test and see if it works!

     

    Try this OneDrive link to a PBIX example I created for you.

    I will delete it after a few days.

    PBIX example report