Forum Discussion
How can I filter a table by two columns in Power BI
- Jan 21, 2022I would suggest creating a helper column with a formula like:
="Q"&INT(MONTH([Date])/4)+1 & "-" & YEAR([Date]) & "-" & [Country]
Then filter out "Q2-2021-US"
=FILTER(A2:D22,(C2:C22<>"US")+((C2:C22="US")*(D2:D22<>8)))
If you work with Office365 or 2021 you can apply FILTER function as well.
- mtarlerJan 21, 2022Silver ContributorI would suggest creating a helper column with a formula like:
="Q"&INT(MONTH([Date])/4)+1 & "-" & YEAR([Date]) & "-" & [Country]
Then filter out "Q2-2021-US"- carloswalderJan 24, 2022Copper Contributor
This was the right hint, as I need to do this in power query, my formular now looks like this - this of course can be optimized:
#"Extracted Year" = Table.TransformColumns(#"Added Custom",{{"Quarter", Date.Year, Int64.Type}}),
#"Changed Type1" = Table.TransformColumnTypes(#"Extracted Year",{{"Quarter", type text}}),
#"Renamed Columns1" = Table.RenameColumns(#"Changed Type1",{{"Quarter", "Year"}}),
#"Added Custom1" = Table.AddColumn(#"Renamed Columns1", "Quarter", each [WKOrderIntakeDate]),
#"Calculated Quarter" = Table.TransformColumns(#"Added Custom1",{{"Quarter", Date.QuarterOfYear, Int64.Type}}),
#"Changed Type2" = Table.TransformColumnTypes(#"Calculated Quarter",{{"Quarter", type text}}),
#"Added Custom2" = Table.AddColumn(#"Changed Type2", "BU", each [WKBusinessUnit]),
#"Changed Type3" = Table.TransformColumnTypes(#"Added Custom2",{{"BU", type text}}),
#"Added Custom3" = Table.AddColumn(#"Changed Type3", "BU & QUARTER", each "Q" & [Quarter] & "BU" & [BU] & "Y" & [Year]),
#"Filtered Rows5" = Table.SelectRows(#"Added Custom3", each [#"BU & QUARTER"] <> "Q2BU3Y2021")
in
#"Filtered Rows5"- SergeiBaklanJan 24, 2022Diamond Contributor
In general you may create column for filtering at once
... #"Changed Type" = Table.TransformColumnTypes( PrevStep, { {"Date", type date}, {"WKBusinessUnit", type text} }), #"Inserted Filter" = Table.AddColumn( #"Changed Type", "Filter", each "Q" & Text.From( Date.QuarterOfYear([Date]) ) & "BU" & [WKBusinessUnit] & "Y" & Text.From( Date.Year( [Date] )), type text) in #"Inserted Filter"
and apply to it filter with parameter like Q2BU3Y2021