13. DAX: Data Analysis Expressions
13.9 FILTER
FILTER(<table>, <condition>) returns a table containing fakt the rows where the condition is true. It is an iterator. Use it when the condition involves a measure or complex logic across columns.
Loyal Customers =
COUNTROWS(
FILTER(VALUES(Customer[Customer ID]), [Total Orders] >= 10)
)
Sales from Loyal Customers =
CALCULATE(
[Total Sales],
FILTER(VALUES(Customer[Customer ID]), [Total Orders] >= 10)
)
Slow Stores =
COUNTROWS(
FILTER(VALUES(DarkStore[Store ID]), [Avg Delivery Time (mins)] > 15)
)
Do not FILTER a whole table when a column filter is enough
CALCULATE([Total Sales], FILTER(Orders, Orders[Discount] > 0)) works but iterates (एकेक ओळ फिरून हिशोब करणे) the entire fact table and can be slow. The simple form CALCULATE([Total Sales], Orders[Discount] > 0) filters fakt one column and is faster. Filter columns, not tables.
Ravindra Bagale's Tip
Friends, many students forget that FILTER returns a table, and try to use it on its own as a value in a measure. Wrap it in CALCULATE, COUNTROWS or an iterator. For conditions on a measure, filter a small column list: FILTER(VALUES(Customer[Customer ID]), [Total Sales] > 2000). This matters for both exams and interviews.
Ravindra Bagale's Tip – मराठी
मित्रांनो, बरेच students विसरतात की FILTER table देतं, आणि ते measure मध्ये एकटंच value म्हणून वापरायचा प्रयत्न करतात. ते CALCULATE, COUNTROWS किंवा iterator मध्ये गुंडाळा. Measure वरच्या conditions साठी columns ची छोटी list filter करा: FILTER(VALUES(Customer[Customer ID]), [Total Sales] > 2000). हे exam आणि interview दोन्हीसाठी important आहे.
Ravindra Bagale's Tip – हिंदी
दोस्तों, बहुत से students भूल जाते हैं कि FILTER table देता है, और उसे measure में अकेले value की तरह इस्तेमाल करने की कोशिश करते हैं. उसे CALCULATE, COUNTROWS या किसी iterator में लपेटो. Measure पर conditions के लिए column की छोटी list filter करो: FILTER(VALUES(Customer[Customer ID]), [Total Sales] > 2000). यह exam और interview दोनों के लिए ज़रूरी है.