<?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: Selectedmeasureformatstring DAX Calculation Item in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selectedmeasureformatstring-DAX-Calculation-Item/m-p/3680149#M142901</link>
    <description>&lt;P&gt;Thank you Albert He&lt;/P&gt;</description>
    <pubDate>Mon, 05 Feb 2024 11:42:48 GMT</pubDate>
    <dc:creator>MrRong</dc:creator>
    <dc:date>2024-02-05T11:42:48Z</dc:date>
    <item>
      <title>Selectedmeasureformatstring DAX Calculation Item</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selectedmeasureformatstring-DAX-Calculation-Item/m-p/3676771#M142770</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ran into an error while trying to create a Calculation Group.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a Measure:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see, the data type depends on the CalcType.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I created a Test calculation group:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With Calculation items:&lt;/P&gt;&lt;P&gt;1) Actual&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) Actual PY&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3) Variance PY&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Matrix visual works fine with Actual and Actual PY.&lt;/P&gt;&lt;P&gt;However, as soon as I created the Variance PY, the visual has this error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It relates to the CalcType=3, FORMAT([PL_%_of_Revenue_Actual],"0.00%")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been trying to troubleshoot the error. The possible solution is &lt;STRONG&gt;Selectedmeasureformatstring&lt;/STRONG&gt; DAX measure in the Dynamic Format String.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am unable how to apply to my Calculation Item measure.&lt;/P&gt;&lt;P&gt;Can someone please help?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks very much&lt;/P&gt;</description>
      <pubDate>Sat, 03 Feb 2024 05:30:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selectedmeasureformatstring-DAX-Calculation-Item/m-p/3676771#M142770</guid>
      <dc:creator>MrRong</dc:creator>
      <dc:date>2024-02-03T05:30:50Z</dc:date>
    </item>
    <item>
      <title>Re: Selectedmeasureformatstring DAX Calculation Item</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selectedmeasureformatstring-DAX-Calculation-Item/m-p/3678266#M142816</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="428418" data-lia-user-login="MrRong" class="lia-mention lia-mention-user"&gt;MrRong&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, I believe you're correct in identifying the issue, and part of the solution (dynamic format string) &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The issue is:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;STRONG&gt;PL_Total_Amount_Actual_2&lt;/STRONG&gt; returns a text value for CalcType = 3 or CalcType =4.&lt;/LI&gt;
&lt;LI&gt;In this case, when the calculation item "Variance PY" is applied to this measure, the text values containing the "%" character cannot be cast as numbers, so an error is returned.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;My recommendation would be to:&lt;/P&gt;
&lt;P&gt;1. Adjust the&amp;nbsp;&lt;STRONG&gt;PL_Total_Amount_Actual_2&amp;nbsp;&lt;/STRONG&gt;measure so that it always returns a numerical value:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;PL_Total_Amount_Actual_2 =
VAR CalcType =
    SELECTEDVALUE ( PL_header[CalcType] )
VAR DisplayDetailCode =
    SELECTEDVALUE ( PL_header[Detail] )
VAR isSubHeaderVisible =
    ISFILTERED ( PL_accounts[Subheader] )
VAR Result =
    SWITCH (
        TRUE (),
        isSubHeaderVisible = TRUE ()
            &amp;amp;&amp;amp; DisplayDetailCode = 0, BLANK (),
        CalcType = 1, [PL_additive_total_Actual],
        CalcType = 2, [PL_running_total_Actual],
        CalcType = 3, [PL_%_of_Revenue_Actual],
        CalcType = 4, [PL_%_of_running_Total_Actual]
    )
RETURN
    Result&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Give the &lt;STRONG&gt;PL_Total_Amount_Actual_2&amp;nbsp;&lt;/STRONG&gt;measure a dynamic format string similar to this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;VAR DefaultFormat = "#,##0;(#,##0);-" -- change as needed
VAR PercentageFormat = "0.00%"
VAR CalcType =
	SELECTEDVALUE ( PL_header[CalcType] )
VAR DisplayDetailCode =
	SELECTEDVALUE ( PL_header[Detail] )
VAR isSubHeaderVisible =
	ISFILTERED ( PL_accounts[Subheader] )
VAR Result =
	SWITCH (
		TRUE (),
		-- This first condition can be omitted if you like, since measure is blank
		isSubHeaderVisible = TRUE () &amp;amp;&amp;amp; DisplayDetailCode = 0, BLANK (),
		CalcType IN { 1, 2 }, DefaultFormat,
		CalcType IN { 3, 4 }, PercentageFormat
	)
RETURN
	Result&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3.&amp;nbsp; For the calculation group, ensure that each calculation item has format string expression&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;SELECTEDMEASUREFORMATSTRING ()&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does this fix it for you?&lt;/P&gt;
&lt;P&gt;Please post back if needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Sun, 04 Feb 2024 05:16:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selectedmeasureformatstring-DAX-Calculation-Item/m-p/3678266#M142816</guid>
      <dc:creator>OwenAuger</dc:creator>
      <dc:date>2024-02-04T05:16:40Z</dc:date>
    </item>
    <item>
      <title>Re: Selectedmeasureformatstring DAX Calculation Item</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selectedmeasureformatstring-DAX-Calculation-Item/m-p/3678374#M142823</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="6799" data-lia-user-login="OwenAuger" class="lia-mention lia-mention-user"&gt;OwenAuger&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for helping me out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I followed your instructions but it is still giving me the error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) Measure is updated:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2)&amp;nbsp;&lt;STRONG&gt;PL_Total_Amount_Actual_2&amp;nbsp;&lt;/STRONG&gt;&lt;SPAN&gt;measure a dynamic format string&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3) Each Calculation Item have format string&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error in the Matrix visual is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do my Calculation Items have correct DAX measure?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wonder that if we need a DAX in the Dynamic format string for the 3 Calculation Items?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Feb 2024 10:44:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selectedmeasureformatstring-DAX-Calculation-Item/m-p/3678374#M142823</guid>
      <dc:creator>MrRong</dc:creator>
      <dc:date>2024-02-04T10:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: Selectedmeasureformatstring DAX Calculation Item</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selectedmeasureformatstring-DAX-Calculation-Item/m-p/3679508#M142875</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="428418" data-lia-user-login="MrRong" class="lia-mention lia-mention-user"&gt;MrRong&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;To troubleshoot this problem, this function can be used in the dynamic format of the MEASURE. This DAX function returns the format string set for the currently evaluated metric. You can then use conditional logic to set the format string dynamically based on SELECTEDMEASUREFORMATSTRING.To solve this problem, this function can be used in the dynamic format of the MEASURE. This DAX function returns the format string set for the currently evaluated metric. You can then use conditional logic to set the format string dynamically based on&amp;nbsp;SELECTEDMEASUREFORMATSTRING.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;VAR CurrentFormatString = SELECTEDMEASUREFORMATSTRING()
VAR CalcType = SELECTEDVALUE ( PL_header[CalcType] )

RETURN
SWITCH (
    TRUE(),
     CalcType = 1, [PL_additive_total_Actual],
     CalcType = 2, [PL_running_total_Actual],
     CalcType = 3, [PL_%_of_Revenue_Actual],
     CalcType = 4, [PL_%_of_running_Total_Actual]
    CurrentFormatString 
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;For more information on how to use&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;, please refer to the official documentation&lt;BR /&gt;&lt;A href="https://learn.microsoft.com/en-us/dax/selectedmeasureformatstring-function-dax" target="_blank"&gt;SELECTEDMEASUREFORMATSTRING function (DAX) - DAX | Microsoft Learn&lt;/A&gt;&lt;BR /&gt;For more information on calculating group formats, you can refer to these documents&lt;BR /&gt;&lt;A href="https://www.sqlbi.com/articles/dynamic-format-strings-with-calculation-groups/" target="_blank"&gt;Dynamic format strings with calculation groups - SQLBI&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://www.sqlbi.com/articles/controlling-format-strings-in-calculation-groups/" target="_blank"&gt;Controlling Format Strings in Calculation Groups - SQLBI&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: SegoeUI; font-size: 11.25pt; color: black;"&gt;&lt;SPAN&gt;Best regards&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: SegoeUI; font-size: 11.25pt; color: black;"&gt;&lt;SPAN&gt;Albert He&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: SegoeUI; font-size: 11.25pt; color: black;"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: SegoeUI; font-size: 11.25pt; color: black;"&gt;&lt;SPAN&gt;If this &lt;EM&gt;&lt;STRONG&gt;post&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;helps&lt;/SPAN&gt;&lt;SPAN&gt;, then please consider&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;Accept it as the solution&lt;/STRONG&gt;&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;to help the other members find it more quickly&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2024 07:32:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selectedmeasureformatstring-DAX-Calculation-Item/m-p/3679508#M142875</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-02-05T07:32:00Z</dc:date>
    </item>
    <item>
      <title>Re: Selectedmeasureformatstring DAX Calculation Item</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selectedmeasureformatstring-DAX-Calculation-Item/m-p/3679904#M142889</link>
      <description>&lt;P&gt;Hi again&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="428418" data-lia-user-login="MrRong" class="lia-mention lia-mention-user"&gt;MrRong&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I see Anonymous&lt;/a&gt;&amp;nbsp;has also replied but I'll reply directly to your post.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Measure looks good &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;2. The measure's dynamic format string looks good &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;3. The calculation items don't look right.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The&amp;nbsp;calculation item expressions for Actual, Actual PY and Variance PY should remain unchanged from your original version, i.e. including&lt;STRONG&gt; SELECTEDMEASURE() &lt;/STRONG&gt;within the expressions.&lt;/LI&gt;
&lt;LI&gt;However, you should enable &lt;STRONG&gt;Dynamic format string&amp;nbsp;&lt;/STRONG&gt;for each calculation item and set it to&lt;STRONG&gt; SELECTEDMEASUREFORMATSTRING().&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;Generally speaking, it would only make sense to use &lt;STRONG&gt;SELECTEDMEASUREFORMATSTRING()&lt;/STRONG&gt; within the Format string expression, not the calculation item expression itself.&lt;/LI&gt;
&lt;LI&gt;The overall purpose of my suggestions were to ensure the measure (with calculation items applied) returns numerical values, and the formatting is controlled solely by format strings.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Sample screenshots:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2024 10:00:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selectedmeasureformatstring-DAX-Calculation-Item/m-p/3679904#M142889</guid>
      <dc:creator>OwenAuger</dc:creator>
      <dc:date>2024-02-05T10:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: Selectedmeasureformatstring DAX Calculation Item</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selectedmeasureformatstring-DAX-Calculation-Item/m-p/3680149#M142901</link>
      <description>&lt;P&gt;Thank you Albert He&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2024 11:42:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selectedmeasureformatstring-DAX-Calculation-Item/m-p/3680149#M142901</guid>
      <dc:creator>MrRong</dc:creator>
      <dc:date>2024-02-05T11:42:48Z</dc:date>
    </item>
    <item>
      <title>Re: Selectedmeasureformatstring DAX Calculation Item</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selectedmeasureformatstring-DAX-Calculation-Item/m-p/3680153#M142902</link>
      <description>Hi Owen, You are spot on the solution. It is great how you troubleshoot the issue, it is very professional. Thanks again, Jimmy Truong</description>
      <pubDate>Mon, 05 Feb 2024 11:44:44 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selectedmeasureformatstring-DAX-Calculation-Item/m-p/3680153#M142902</guid>
      <dc:creator>MrRong</dc:creator>
      <dc:date>2024-02-05T11:44:44Z</dc:date>
    </item>
  </channel>
</rss>

