{"id":10417,"date":"2020-12-03T16:23:33","date_gmt":"2020-12-04T00:23:33","guid":{"rendered":"https:\/\/threecloud.wpengine.com\/post\/setting-variables-using-dax-in-power-bi\/"},"modified":"2023-07-31T10:00:53","modified_gmt":"2023-07-31T17:00:53","slug":"setting-variables-using-dax-in-power-bi","status":"publish","type":"post","link":"https:\/\/3cloudsolutions.com\/resources\/setting-variables-using-dax-in-power-bi\/","title":{"rendered":"Setting Variables Using DAX in Power BI"},"content":{"rendered":"<p>Welcome to another Azure Every Day focused on one of my favorite topics, using DAX in Power BI. In a previous post, I covered a couple of my favorite DAX formulas, CALCULATE and FILTER. Here, I\u2019ll discuss variables and how to work those into CALCULATE\/FILTER to expand on that and make it even more powerful. You may want to check out my previous post here, as I\u2019ll be continuing using that demo.<\/p>\n<ul>\n<li>I started by building in a CALCULATE\/FILTER function in a table to calculate the beginning balance for 2017 for all my assets.<\/li>\n<li>My code (see my video demo for code detail) tells it to calculate the sum of the beginning balance and I filtered the table where fiscal year equals 2017, and finance type equals assets.<\/li>\n<li>Now, let\u2019s say we want to know the assets for every year, not just 2017. To do this, we need to set the year into a variable and then it will calculate that asset for each individual year.<\/li>\n<li>You use the VAR function to set the variable in the code and you\u2019ll need to give it a name. In my case I\u2019ll use YR for year and I\u2019ll have that EQUAL to the fiscal year. It\u2019s important to note that anytime you set a variable, you must hit return at the end.<\/li>\n<li>Next, I\u2019m going to update my FILTER. My code is calculating the sum of the beginning balance and I\u2019m filtering the table where fiscal year equals 2017, but now I want to take that out and change it to fiscal year equals year.<\/li>\n<li>How this works is when this goes through each row it will calculate for each year by using the variable instead of hard coding the year into there.<\/li>\n<li>So previously we only had one outcome for 2017, now when we submit this, we\u2019ll see four outcomes as we have four years\u2019 worth of data, so we\u2019re getting a calculation for our beginning balance for each year.<\/li>\n<li>We can even step this up a bit if we wanted not only the beginning balance for each year, but also for each finance type. Maybe we don\u2019t just want the assets but other values like equity, expense or liability.<\/li>\n<li>All we need to do is set another variable that I\u2019ll call FT for finance type. And instead of doing this for where finance type equals asset, we\u2019ll say where finance type equals our variable.<\/li>\n<li>Now we\u2019ll have the calculation for every year for every individual finance type.<\/li>\n<\/ul>\n<p><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/QCw_NKmsUlE\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><br \/>\nI hope this quick example helps you to start using these DAX formulas in your reports. The CALCULATE\/FILTER functions and using variables are something I use all the time in Power BI.<\/p>\n<p>Need further help? Our expert team and solution offerings can help your business with any Azure product or service, including Managed Services offerings. Contact us at 888-8AZURE or\u00a0 <a href=\"mailto:sales@3cloudsolutions.com\">sales@3cloudsolutions.com<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to another Azure Every Day focused on one of my favorite topics, using DAX&mldr;<\/p>\n","protected":false},"author":36,"featured_media":10714,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"content-type":"","footnotes":""},"categories":[260],"tags":[273],"class_list":["post-10417","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-ai","tag-power-bi","topics-blog"],"acf":[],"_links":{"self":[{"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/posts\/10417","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/users\/36"}],"replies":[{"embeddable":true,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/comments?post=10417"}],"version-history":[{"count":0,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/posts\/10417\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/media\/10714"}],"wp:attachment":[{"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/media?parent=10417"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/categories?post=10417"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/tags?post=10417"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}