<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: DAX Measure with SWITCH in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Measure-with-SWITCH/m-p/3948200#M153374</link>
    <description>&lt;P&gt;The error you’re encountering is because DAX is expecting a single value for the ‘LicenseExpireDays’ column in the ‘Agent Licenses’ table, but it’s getting multiple values because of the one-to-many relationship between the ‘Agent’ and ‘Agent Licenses’ tables.&lt;/P&gt;&lt;P&gt;In DAX, when you reference a column directly, it expects a single value. If there are multiple values (as in a column of a table), you need to use an aggregation function to get a single result, such as&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;MIN,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;MAX,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;COUNT,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;SUM, etc.&lt;/P&gt;&lt;P&gt;In your case, you’re trying to create a measure that depends on the value of ‘LicenseExpireDays’ for each row in the ‘Agent Licenses’ table. You can achieve this by using the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;CALCULATE&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;FILTER&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;functions in DAX. Here’s how you can modify your ‘Test2’ measure:&lt;/P&gt;&lt;DIV class=""&gt;&lt;PRE&gt;Test2 = 
CALCULATE(
    COUNT('Agent Licenses'[LicenseExpireDays]),
    FILTER(
        'Agent Licenses',
        'Agent Licenses'[LicenseExpireDays] = 0
    )
)&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;This measure will count the number of ‘LicenseExpireDays’ that are equal to 0. If you want to return “Expired” when ‘LicenseExpireDays’ is 0 and “OK” otherwise, you can create a calculated column instead of a measure:&lt;/P&gt;&lt;DIV class=""&gt;&lt;PRE&gt;LicenseStatus = 
SWITCH(
    TRUE(),
    'Agent Licenses'[LicenseExpireDays] = 0, "Expired",
    "OK"
)&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;This calculated column will add a new column ‘LicenseStatus’ to the ‘Agent Licenses’ table. For each row in the table, if ‘LicenseExpireDays’ is 0, ‘LicenseStatus’ will be “Expired”. Otherwise, ‘LicenseStatus’ will be “OK”.&lt;/P&gt;</description>
    <pubDate>Fri, 24 May 2024 17:14:00 GMT</pubDate>
    <dc:creator>Kaviraj11</dc:creator>
    <dc:date>2024-05-24T17:14:00Z</dc:date>
    <item>
      <title>DAX Measure with SWITCH</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Measure-with-SWITCH/m-p/3948101#M153371</link>
      <description>&lt;P&gt;I have 2 tables, Agent and Agent Licenses with a 1 to many relationship.&amp;nbsp; On the the Agent Licenses table there is a column called&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;LicenseExpireDays.&amp;nbsp; I want to create a chart showing expired, will expire in 7 days, etc.&amp;nbsp; The issue is I get a DAX error message when I reference&amp;nbsp;LicenseExpireDays in the swtich command, but it has no issues if I just count on the field.&amp;nbsp; For example this is fine:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Test =&lt;/SPAN&gt; &lt;SPAN&gt;Count&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'Agent Licenses'&lt;/SPAN&gt;&lt;SPAN&gt;[LicenseExpireDays]&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;But this isn't:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Test2 = &lt;/SPAN&gt;&lt;SPAN&gt;SWITCH&lt;/SPAN&gt;&lt;SPAN&gt;('Agent Licenses'[LicenseExpireDays] = &lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"Expired"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;"OK"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Exact error is A single value for column 'LicenseExpireDays' in table 'Agent Licenses' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I tried defining&amp;nbsp;LicenseExpireDays as a count but still the same result.&amp;nbsp; What am I missing?&amp;nbsp; Thank you.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 24 May 2024 16:21:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Measure-with-SWITCH/m-p/3948101#M153371</guid>
      <dc:creator>PSHAW</dc:creator>
      <dc:date>2024-05-24T16:21:41Z</dc:date>
    </item>
    <item>
      <title>Re: DAX Measure with SWITCH</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Measure-with-SWITCH/m-p/3948200#M153374</link>
      <description>&lt;P&gt;The error you’re encountering is because DAX is expecting a single value for the ‘LicenseExpireDays’ column in the ‘Agent Licenses’ table, but it’s getting multiple values because of the one-to-many relationship between the ‘Agent’ and ‘Agent Licenses’ tables.&lt;/P&gt;&lt;P&gt;In DAX, when you reference a column directly, it expects a single value. If there are multiple values (as in a column of a table), you need to use an aggregation function to get a single result, such as&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;MIN,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;MAX,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;COUNT,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;SUM, etc.&lt;/P&gt;&lt;P&gt;In your case, you’re trying to create a measure that depends on the value of ‘LicenseExpireDays’ for each row in the ‘Agent Licenses’ table. You can achieve this by using the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;CALCULATE&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;FILTER&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;functions in DAX. Here’s how you can modify your ‘Test2’ measure:&lt;/P&gt;&lt;DIV class=""&gt;&lt;PRE&gt;Test2 = 
CALCULATE(
    COUNT('Agent Licenses'[LicenseExpireDays]),
    FILTER(
        'Agent Licenses',
        'Agent Licenses'[LicenseExpireDays] = 0
    )
)&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;This measure will count the number of ‘LicenseExpireDays’ that are equal to 0. If you want to return “Expired” when ‘LicenseExpireDays’ is 0 and “OK” otherwise, you can create a calculated column instead of a measure:&lt;/P&gt;&lt;DIV class=""&gt;&lt;PRE&gt;LicenseStatus = 
SWITCH(
    TRUE(),
    'Agent Licenses'[LicenseExpireDays] = 0, "Expired",
    "OK"
)&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;This calculated column will add a new column ‘LicenseStatus’ to the ‘Agent Licenses’ table. For each row in the table, if ‘LicenseExpireDays’ is 0, ‘LicenseStatus’ will be “Expired”. Otherwise, ‘LicenseStatus’ will be “OK”.&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2024 17:14:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Measure-with-SWITCH/m-p/3948200#M153374</guid>
      <dc:creator>Kaviraj11</dc:creator>
      <dc:date>2024-05-24T17:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: DAX Measure with SWITCH</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Measure-with-SWITCH/m-p/3948375#M153379</link>
      <description>&lt;P&gt;Thanks for the explaination.&amp;nbsp; The calculated column was exactly what I needed.&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2024 18:56:39 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Measure-with-SWITCH/m-p/3948375#M153379</guid>
      <dc:creator>PSHAW</dc:creator>
      <dc:date>2024-05-24T18:56:39Z</dc:date>
    </item>
  </channel>
</rss>

