{"id":90,"date":"2026-02-26T05:02:45","date_gmt":"2026-02-26T05:02:45","guid":{"rendered":"https:\/\/gigz.pk\/powerbi\/?post_type=lesson&#038;p=90"},"modified":"2026-03-17T05:45:02","modified_gmt":"2026-03-17T05:45:02","slug":"logical-functions-if-switch","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/powerbi\/lesson\/logical-functions-if-switch\/","title":{"rendered":"Logical Functions (IF, SWITCH)"},"content":{"rendered":"\n<p>Logical functions in DAX are used to apply conditions in calculations. They help you create rules, categorize data, and build dynamic measures based on specific criteria.<\/p>\n\n\n\n<p>The two most commonly used logical functions in DAX are IF and SWITCH.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">IF Function<\/h2>\n\n\n\n<p>The IF function checks a condition and returns one value if the condition is TRUE and another value if it is FALSE.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Syntax<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">IF(logical_test, value_if_true, value_if_false)<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Example 1 \u2013 Basic Condition<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">Profit Status = IF(Sales[Profit] &gt; 0, \"Profit\", \"Loss\")<\/pre>\n\n\n\n<p>This calculated column checks if Profit is greater than 0.<br>If TRUE, it returns &#8220;Profit&#8221;; otherwise, it returns &#8220;Loss&#8221;.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example 2 \u2013 Measure with IF<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">High Sales = IF(SUM(Sales[Amount]) &gt; 100000, \"Target Achieved\", \"Below Target\")<\/pre>\n\n\n\n<p>This measure dynamically evaluates total sales based on filter context.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">When to Use IF<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Categorizing data (Pass\/Fail, Profit\/Loss)<\/li>\n\n\n\n<li>Creating performance indicators<\/li>\n\n\n\n<li>Applying simple conditional logic<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">SWITCH Function<\/h2>\n\n\n\n<p>The SWITCH function is used when you need to evaluate multiple conditions. It is cleaner and more readable than using multiple nested IF statements.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Syntax<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">SWITCH(expression, value1, result1, value2, result2, ..., else_result)<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Example 1 \u2013 Category Mapping<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">Sales Category =<br>SWITCH(<br>    TRUE(),<br>    Sales[Amount] &gt;= 100000, \"High\",<br>    Sales[Amount] &gt;= 50000, \"Medium\",<br>    Sales[Amount] &gt;= 10000, \"Low\",<br>    \"Very Low\"<br>)<\/pre>\n\n\n\n<p>Here, SWITCH(TRUE()) allows you to evaluate multiple logical conditions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example 2 \u2013 Based on Exact Match<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">Region Name =<br>SWITCH(<br>    Sales[RegionCode],<br>    1, \"North\",<br>    2, \"South\",<br>    3, \"East\",<br>    4, \"West\",<br>    \"Unknown\"<br>)<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">When to Use SWITCH<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>When handling multiple conditions<\/li>\n\n\n\n<li>Replacing nested IF statements<\/li>\n\n\n\n<li>Mapping codes to readable labels<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">IF vs SWITCH<\/h2>\n\n\n\n<p>IF is best for simple two-condition logic.<\/p>\n\n\n\n<p>SWITCH is better for handling multiple conditions and improves readability.<\/p>\n\n\n\n<p>Using SWITCH makes your DAX cleaner and easier to maintain.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Logical functions like IF and SWITCH allow you to apply decision-making logic in your data model. They are essential for categorization, KPI evaluation, and building intelligent Power BI reports.<\/p>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1773726475556\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/powerbi\/\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">Power BI DAX Mastery > DAX Fundamentals > Logical Functions (IF, SWITCH)<\/span><\/span><\/div>","protected":false},"menu_order":27,"template":"","class_list":["post-90","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Logical Functions (IF, SWITCH) - Power BI Learning Hub<\/title>\n<meta name=\"description\" content=\"Master DAX logical functions IF and SWITCH in Power BI. Learn conditional logic for categorization and dynamic measures.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Logical Functions (IF, SWITCH) - Power BI Learning Hub\" \/>\n<meta property=\"og:description\" content=\"Master DAX logical functions IF and SWITCH in Power BI. Learn conditional logic for categorization and dynamic measures.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/\" \/>\n<meta property=\"og:site_name\" content=\"Power BI Learning Hub\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-17T05:45:02+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/powerbi\\\/lesson\\\/logical-functions-if-switch\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/\",\"name\":\"Logical Functions (IF, SWITCH) - Power BI Learning Hub\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/powerbi\\\/#website\"},\"datePublished\":\"2026-02-26T05:02:45+00:00\",\"dateModified\":\"2026-03-17T05:45:02+00:00\",\"description\":\"Master DAX logical functions IF and SWITCH in Power BI. Learn conditional logic for categorization and dynamic measures.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/powerbi\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Power BI DAX Mastery > DAX Fundamentals > Logical Functions (IF, SWITCH)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/powerbi\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/powerbi\\\/\",\"name\":\"Power BI Learning Hub\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/powerbi\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Logical Functions (IF, SWITCH) - Power BI Learning Hub","description":"Master DAX logical functions IF and SWITCH in Power BI. Learn conditional logic for categorization and dynamic measures.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gigz.pk\/","og_locale":"en_US","og_type":"article","og_title":"Logical Functions (IF, SWITCH) - Power BI Learning Hub","og_description":"Master DAX logical functions IF and SWITCH in Power BI. Learn conditional logic for categorization and dynamic measures.","og_url":"https:\/\/gigz.pk\/","og_site_name":"Power BI Learning Hub","article_modified_time":"2026-03-17T05:45:02+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/powerbi\/lesson\/logical-functions-if-switch\/","url":"https:\/\/gigz.pk\/","name":"Logical Functions (IF, SWITCH) - Power BI Learning Hub","isPartOf":{"@id":"https:\/\/gigz.pk\/powerbi\/#website"},"datePublished":"2026-02-26T05:02:45+00:00","dateModified":"2026-03-17T05:45:02+00:00","description":"Master DAX logical functions IF and SWITCH in Power BI. Learn conditional logic for categorization and dynamic measures.","breadcrumb":{"@id":"https:\/\/gigz.pk\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/powerbi\/"},{"@type":"ListItem","position":2,"name":"Power BI DAX Mastery > DAX Fundamentals > Logical Functions (IF, SWITCH)"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/powerbi\/#website","url":"https:\/\/gigz.pk\/powerbi\/","name":"Power BI Learning Hub","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/powerbi\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/powerbi\/wp-json\/wp\/v2\/lesson\/90","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/powerbi\/wp-json\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/powerbi\/wp-json\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/powerbi\/wp-json\/wp\/v2\/media?parent=90"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}