Forum Discussion

b2wise's avatar
b2wise
Helper III
5 years ago
Solved

Count With Multiple Conditions - DAX

Hi,   I'm trying to count orders that must ship today using a DAX formula and am getting no results. Must ship orders are determined by: Date created Time created Host priority The busin...
  • v-xiaotang's avatar
    5 years ago

    Hi b2wise 

    I create a sample file under DQ mode, here is my operation steps.

    -

    Change the type of column [Date Created] to Date

    Since type of your 3 columns is text and can’t be changed, so create the measures bellow.

     

     

     

    sortbytime = //we need to create this measure so that we can sort by [Time Created], because type of this column is text
    VAR _timecreated =
        SELECTEDVALUE ( Headers[Time Created] )
    RETURN
        VALUE ( LEFT ( _timecreated, 2 ) ) * 100
            + VALUE ( MID ( _timecreated, 4, 2 ) )
    get priority = //the reason to create this measure is same as the measure above
    VAR _pri =
        SELECTEDVALUE ( Headers[Host Priority] )
    VAR _lenvalue =
        IF ( LEN ( _pri ) > 1, LEN ( _pri ) - 1 )
    VAR _getnumfromtext =
        RIGHT ( _pri, _lenvalue )
    VAR _vau =
        IF ( ISERROR ( VALUE ( _pri ) ), _getnumfromtext, VALUE ( _pri ) )
    RETURN
        _vau

     

     

    then, create the measure count and put it in the Card visual.

     

     

    count =
    VAR _timecreated =
        SELECTEDVALUE ( Headers[Time Created] )
    VAR _time =
        VALUE ( LEFT ( _timecreated, 2 ) ) * 100
            + VALUE ( MID ( _timecreated, 4, 2 ) )
    VAR _count =
        CALCULATE (
            COUNTROWS ( Headers ),
            FILTER (
                ALL ( Headers ),
                (
                    Headers[Date Created] < DATE ( 2021, 5, 25 )//I replace your MAX ( 'Current Date Time'[Date] ) with DATE ( 2021, 5, 25 ), because I dont know the structure of 'Current Date Time'[Date], you can change it back later.
                        && [get priority] >= 1
                        && [get priority] <= 29
                )
                    || (
                        Headers[Date Created] = DATE ( 2021, 5, 25 )
                            && [get priority] >= 10
                            && [sortbytime] < 1515
                    )
                    || (
                        Headers[Date Created] = DATE ( 2021, 5, 25 )
                            && [get priority] < 10
                            && [sortbytime] < 1615
                    )
            )
        )
    RETURN
        _count

     

     

     

    Result:

     

    Best Regards,

    Community Support Team _ Tang

    If this post helps, please consider Accept it as the solution to help the other members find it more quickly.