Forum Discussion

GSPBI's avatar
GSPBI
Frequent Visitor
5 years ago
Solved

Filter out rows based on two columns (in DAX)

Dear Microsoft PowerBI community,

 

I have been a long time user of this forum and I really appreciate all the users that raised their queries and the those that respond to them.

 

I have come across an issue that seems easy but I can't figure it out.

 

I have a table that looks like the below in the query editor.

 

PackagePlanned/ActualMilestone AMilestone B
A

Planned

12/08/202111/09/2021
AActual12/08/2021null
BPlanned13/08/202111/09/2021
BActualnull14/08/2021
CPlanned10/09/202112/08/2021
CActual10/09/202113/08/2021

 

I have created a conditional column in the query editor to say yes if the date is in the last 4 weeks from today.

 

PackagePlanned/ActualMilestone ACheck AMilestone BCheck B
A

Planned

12/08/2021No11/09/2021No
AActual12/08/2021NonullNo
BPlanned13/08/2021Yes11/09/2021No
BActualnullNo14/08/2021Yes
CPlanned10/09/2021Yes12/08/2021No
CActual10/09/2021Yes13/08/2021Yes

 

I am using this conditional column to filter the dates that are depicted in two separate tables. If yes, then show the dates.

 

The resultant first table is this:

PackagePlanned/ActualMilestone ACheck A
BPlanned13/08/2021Yes
CPlanned10/09/2021Yes
CActual10/09/2021Yes

 

I only want to show the actual date if there's both a planned and an actual date and I want to keep the planned date if there is only a planned date. So I am looking for the following result:

 

PackagePlanned/ActualMilestone ACheck A
BPlanned13/08/2021Yes
CActual10/09/2021Yes

 

Is there a dax query that can help me apply this filter?

 

Any guidance would be appreciated.

 

Kind regards,

GSPBI

  • Hi, GSPBI 

     

    You can create a measure and use it in filter pane to filter the row you want to show in table.

    Since you have already written Check A, I will directly use column instead. My idea is to divide into two different situations.

    Measure:

    Measure =
    VAR a =
        COUNTX (
            FILTER (
                ALL ( 'Table' ),
                [Check A] = "Yes"
                    && [Package] = SELECTEDVALUE ( 'Table'[Package] )
            ),
            [Package]
        )
    VAR b =
        IF (
            MAX ( 'Table'[Planned/Actual] ) = "Actual"
                && a = 2,
            1,
            IF ( MAX ( 'Table'[Check A] ) = "Yes" && a = 1, 1 )
        )
    RETURN
        b
    

    Did I answer your question ? Please mark my reply as solution. Thank you very much.
    If not, please feel free to ask me.


    Best Regards,

    Community Support Team _ Janey

     

3 Replies

  • v-janeyg-msft's avatar
    v-janeyg-msft
    Icon for Community Support rankCommunity Support

    Hi, GSPBI 

     

    You can create a measure and use it in filter pane to filter the row you want to show in table.

    Since you have already written Check A, I will directly use column instead. My idea is to divide into two different situations.

    Measure:

    Measure =
    VAR a =
        COUNTX (
            FILTER (
                ALL ( 'Table' ),
                [Check A] = "Yes"
                    && [Package] = SELECTEDVALUE ( 'Table'[Package] )
            ),
            [Package]
        )
    VAR b =
        IF (
            MAX ( 'Table'[Planned/Actual] ) = "Actual"
                && a = 2,
            1,
            IF ( MAX ( 'Table'[Check A] ) = "Yes" && a = 1, 1 )
        )
    RETURN
        b
    

    Did I answer your question ? Please mark my reply as solution. Thank you very much.
    If not, please feel free to ask me.


    Best Regards,

    Community Support Team _ Janey

     

  • Mohammad_Refaei's avatar
    Mohammad_Refaei
    Icon for Solution Specialist rankSolution Specialist

    You can keep working with the Query Editor.

    1. Sort Ascending both the date and the Planned/Actual fields.

    Table.Sort(#"Changed Type",{{"Milestone A", Order.Ascending}, {"Planned/Actual", Order.Ascending}})

    2. Wrap the last sorting step by Table.Buffer function

    = Table.Buffer(Table.Sort(#"Changed Type",{{"Milestone A", Order.Ascending}, {"Planned/Actual", Order.Ascending}}))

    3. Remove Duplicates for all columns except Planned/Actual

    = Table.Distinct(#"Sorted Rows", {"Package", "Milestone A", "Check A"})

     

    This will give you whath you are looking for