<?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 how to replicate a specific tableau measure in power bi using DAX in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/how-to-replicate-a-specific-tableau-measure-in-power-bi-using/m-p/3571047#M137686</link>
    <description>&lt;P&gt;I have a critical problem to replicate a tableau measure in power bi using DAX.&lt;/P&gt;&lt;P&gt;this is the tableau measure:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;```
tableau_measure =

[working_time]
/
CASE ([Country])
WHEN 'Italy' THEN 40 * 60 * ({FIXED [Country] : COUNTD(IIF([Flag Working Day Italy]=1,[Calendar Date],NULL))})
WHEN 'Germany' THEN 50 * 60 * ({FIXED [Country] : COUNTD(IIF([Flag Working Day Germany]=1,[Calendar Date],NULL))})
WHEN 'Austria' THEN 40 * 60 * ({FIXED [Country] : COUNTD(IIF([Flag Working Day Austria]=1,[Calendar Date],NULL))})
WHEN 'Poland' THEN 50 * 60 * ({FIXED [Country] : COUNTD(IIF([Flag Working Day Poland]=1,[Calendar Date],NULL))})
WHEN 'Romania' THEN 60 * 60 * ({FIXED [Country] : COUNTD(IIF([Flag Working Day Romania]=1,[Calendar Date],NULL))})
ELSE 315 * ({FIXED [Country] : COUNTD(IIF([Flag Working Day Generic]=1,[Calendar Date],NULL))})
END

```&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;My power BI data model is:&lt;/P&gt;&lt;P&gt;- table_A (fact table) -&amp;gt; contains information about some working activities with relating column working_time (in seconds) and column date_ref (dd-mm-yyyy), and others columns not relevant..&lt;/P&gt;&lt;P&gt;- table_B (dimension table) -&amp;gt; contains column [Country] (as string), and others columns not relevant..&lt;/P&gt;&lt;P&gt;- table_C (dimension table, is a calendar table) -&amp;gt; contains columns such as [Flag Working Day Italy], [Flag Working Day Germany], [Flag Working Day Austria], [Flag Working Day Poland], [Flag Working Day Romania], [Flag Working Day Generic] (these columns contains two different values, e.g. values 1 for working days and values 0 otherwise ) and others columns not relevant..&lt;/P&gt;&lt;P&gt;table_B is related on table_A by one to many cardinality&lt;BR /&gt;table_C is related on table_A by one to many cardinality&lt;BR /&gt;&lt;BR /&gt;I tryied to replicate that measure in DAX as below:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;power_bi_measure =

var num = table_A[working_time]
var den =
SWITCH (
    RELATED ( table_B[Country] ),
    "Italy", 340 * 60 * CALCULATE ( DISTINCTCOUNT ( table_A[date_ref] ), ALL ( table_A), FILTER ( table_C , table_C [flag_working_day_italy] = 1 ) ),
    "Germany", 350 * 60 * CALCULATE ( DISTINCTCOUNT ( table_A[date_ref]), ALL ( table_A), FILTER ( table_C , table_C [flag_working_day_germany] = 1 ) ),
    "Austria", 340 * 60 * CALCULATE ( DISTINCTCOUNT ( table_A[date_ref]), ALL ( table_A), FILTER ( table_C , table_C [flag_working_day_austria] = 1 ) ),
    "Poland", 350 * 60 * CALCULATE ( DISTINCTCOUNT ( table_A[date_ref] ), ALL ( table_A), FILTER ( table_C , table_C [flag_working_day_poland] = 1 ) ),
    "Romania", 360 * 60 * CALCULATE ( DISTINCTCOUNT (table_A[date_ref] ), ALL ( table_A), FILTER ( table_C , table_C [flag_working_day_romania] = 1 ) ),
    315 * CALCULATE ( DISTINCTCOUNT ( table_A[date_ref] ), ALL ( table_A ), FILTER ( table_C , table_C [flag_working_day_generic] = 1 ) )
)

return DIVIDE ( num, den, 0 )&lt;/LI-CODE&gt;&lt;P&gt;On my display page, I have added a slicer that contains the date_ref column, set to the "between" mode, for example, from 10-1-2023 to 11-1-2023.&lt;/P&gt;&lt;P&gt;I am encountering an error in the calculation of working_days because it does not take into account the calendar days (in table_C) within the range of dates filtered in the slicer, specifically the days from 10-1-2023 to 11-1-2023. Instead, it considers only the days in table_A (from 10-1-2023 to 11-1-2023) for which there are working activities.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;For example, considering the above filters, the working days for the country Germany are 22.&lt;/P&gt;&lt;P&gt;(undesired output):&lt;BR /&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;In this case, flag_working_day_germany = 9 is due to the fact that the activities of process_working_activity = BB are present only on 9 calendar days in table_A.&lt;/P&gt;&lt;P&gt;(desired output):&lt;BR /&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Our desired output should consider all values of flag_working_day_germany present in the column, regardless of other activities, and only refer to the filter 10-1-2023, 11-1-2023, resulting in 22 days.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 06 Dec 2023 17:26:20 GMT</pubDate>
    <dc:creator>simon_pbi_92</dc:creator>
    <dc:date>2023-12-06T17:26:20Z</dc:date>
    <item>
      <title>how to replicate a specific tableau measure in power bi using DAX</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/how-to-replicate-a-specific-tableau-measure-in-power-bi-using/m-p/3571047#M137686</link>
      <description>&lt;P&gt;I have a critical problem to replicate a tableau measure in power bi using DAX.&lt;/P&gt;&lt;P&gt;this is the tableau measure:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;```
tableau_measure =

[working_time]
/
CASE ([Country])
WHEN 'Italy' THEN 40 * 60 * ({FIXED [Country] : COUNTD(IIF([Flag Working Day Italy]=1,[Calendar Date],NULL))})
WHEN 'Germany' THEN 50 * 60 * ({FIXED [Country] : COUNTD(IIF([Flag Working Day Germany]=1,[Calendar Date],NULL))})
WHEN 'Austria' THEN 40 * 60 * ({FIXED [Country] : COUNTD(IIF([Flag Working Day Austria]=1,[Calendar Date],NULL))})
WHEN 'Poland' THEN 50 * 60 * ({FIXED [Country] : COUNTD(IIF([Flag Working Day Poland]=1,[Calendar Date],NULL))})
WHEN 'Romania' THEN 60 * 60 * ({FIXED [Country] : COUNTD(IIF([Flag Working Day Romania]=1,[Calendar Date],NULL))})
ELSE 315 * ({FIXED [Country] : COUNTD(IIF([Flag Working Day Generic]=1,[Calendar Date],NULL))})
END

```&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;My power BI data model is:&lt;/P&gt;&lt;P&gt;- table_A (fact table) -&amp;gt; contains information about some working activities with relating column working_time (in seconds) and column date_ref (dd-mm-yyyy), and others columns not relevant..&lt;/P&gt;&lt;P&gt;- table_B (dimension table) -&amp;gt; contains column [Country] (as string), and others columns not relevant..&lt;/P&gt;&lt;P&gt;- table_C (dimension table, is a calendar table) -&amp;gt; contains columns such as [Flag Working Day Italy], [Flag Working Day Germany], [Flag Working Day Austria], [Flag Working Day Poland], [Flag Working Day Romania], [Flag Working Day Generic] (these columns contains two different values, e.g. values 1 for working days and values 0 otherwise ) and others columns not relevant..&lt;/P&gt;&lt;P&gt;table_B is related on table_A by one to many cardinality&lt;BR /&gt;table_C is related on table_A by one to many cardinality&lt;BR /&gt;&lt;BR /&gt;I tryied to replicate that measure in DAX as below:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;power_bi_measure =

var num = table_A[working_time]
var den =
SWITCH (
    RELATED ( table_B[Country] ),
    "Italy", 340 * 60 * CALCULATE ( DISTINCTCOUNT ( table_A[date_ref] ), ALL ( table_A), FILTER ( table_C , table_C [flag_working_day_italy] = 1 ) ),
    "Germany", 350 * 60 * CALCULATE ( DISTINCTCOUNT ( table_A[date_ref]), ALL ( table_A), FILTER ( table_C , table_C [flag_working_day_germany] = 1 ) ),
    "Austria", 340 * 60 * CALCULATE ( DISTINCTCOUNT ( table_A[date_ref]), ALL ( table_A), FILTER ( table_C , table_C [flag_working_day_austria] = 1 ) ),
    "Poland", 350 * 60 * CALCULATE ( DISTINCTCOUNT ( table_A[date_ref] ), ALL ( table_A), FILTER ( table_C , table_C [flag_working_day_poland] = 1 ) ),
    "Romania", 360 * 60 * CALCULATE ( DISTINCTCOUNT (table_A[date_ref] ), ALL ( table_A), FILTER ( table_C , table_C [flag_working_day_romania] = 1 ) ),
    315 * CALCULATE ( DISTINCTCOUNT ( table_A[date_ref] ), ALL ( table_A ), FILTER ( table_C , table_C [flag_working_day_generic] = 1 ) )
)

return DIVIDE ( num, den, 0 )&lt;/LI-CODE&gt;&lt;P&gt;On my display page, I have added a slicer that contains the date_ref column, set to the "between" mode, for example, from 10-1-2023 to 11-1-2023.&lt;/P&gt;&lt;P&gt;I am encountering an error in the calculation of working_days because it does not take into account the calendar days (in table_C) within the range of dates filtered in the slicer, specifically the days from 10-1-2023 to 11-1-2023. Instead, it considers only the days in table_A (from 10-1-2023 to 11-1-2023) for which there are working activities.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;For example, considering the above filters, the working days for the country Germany are 22.&lt;/P&gt;&lt;P&gt;(undesired output):&lt;BR /&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;In this case, flag_working_day_germany = 9 is due to the fact that the activities of process_working_activity = BB are present only on 9 calendar days in table_A.&lt;/P&gt;&lt;P&gt;(desired output):&lt;BR /&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Our desired output should consider all values of flag_working_day_germany present in the column, regardless of other activities, and only refer to the filter 10-1-2023, 11-1-2023, resulting in 22 days.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2023 17:26:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/how-to-replicate-a-specific-tableau-measure-in-power-bi-using/m-p/3571047#M137686</guid>
      <dc:creator>simon_pbi_92</dc:creator>
      <dc:date>2023-12-06T17:26:20Z</dc:date>
    </item>
    <item>
      <title>Re: how to replicate a specific tableau measure in power bi using DAX</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/how-to-replicate-a-specific-tableau-measure-in-power-bi-using/m-p/3573586#M137772</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="657014" data-lia-user-login="simon_pbi_92" class="lia-mention lia-mention-user"&gt;simon_pbi_92&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Please try to use the following measure.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;power_bi_measure = 
VAR num = SUM ( table_A[working_time] )
VAR den = 
    SWITCH (
        TRUE (),
        MAX ( table_B[Country] ) = "Italy", 40 * 60 * COUNTROWS ( FILTER ( table_C, table_C[Flag Working Day Italy] = 1 ) ),
        MAX ( table_B[Country] ) = "Germany", 50 * 60 * COUNTROWS ( FILTER ( table_C, table_C[Flag Working Day Germany] = 1 ) ),
        MAX ( table_B[Country] ) = "Austria", 40 * 60 * COUNTROWS ( FILTER ( table_C, table_C[Flag Working Day Austria] = 1 ) ),
        MAX ( table_B[Country] ) = "Poland", 50 * 60 * COUNTROWS ( FILTER ( table_C, table_C[Flag Working Day Poland] = 1 ) ),
        MAX ( table_B[Country] ) = "Romania", 60 * 60 * COUNTROWS ( FILTER ( table_C, table_C[Flag Working Day Romania] = 1 ) ),
        315 * COUNTROWS ( FILTER ( table_C, table_C[Flag Working Day Generic] = 1 ) )
    )
RETURN
    DIVIDE ( num, den )
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490" target="_blank"&gt;How to Get Your Question Answered Quickly&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards&lt;BR /&gt;Community Support Team _ Rongtie&lt;/P&gt;
&lt;P&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 01:14:24 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/how-to-replicate-a-specific-tableau-measure-in-power-bi-using/m-p/3573586#M137772</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-12-08T01:14:24Z</dc:date>
    </item>
    <item>
      <title>Re: how to replicate a specific tableau measure in power bi using DAX</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/how-to-replicate-a-specific-tableau-measure-in-power-bi-using/m-p/3580319#M138083</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Thank you for the response. Unfortunately, the issue persists.&lt;BR /&gt;Let's simplify the measure in this way, considering only the part that seems to be problematic (related to the calculation of working days), namely:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;countrows_working_day_germany = COUNTROWS ( FILTER ( table_C, tableC[Flag Working Day Germany] = 1 ) )&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;Unfortunately, your measure and mine depend on the dates of the tracked working activities (present in table_A). For example, when I consider a time period, from Oct-1-2023, to Nov-1-2023 (entered in my Power BI page as a slicer), I expect to have 22 working days (in the date field of table_C).&lt;BR /&gt;However, what happens is the following situation:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| process_working_activity | countrows_working_day_germany |
|---------------------------|-------------------------------|
| AA                        | 22                            |
| BB                        | 2                             |
| CC                        | 11                            |&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;Include a description of the situation with values 22, 2, and 11, which depend on the tracked activities on process_working_activity for 22, 2, and 11 distinct days.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;So, the problem is that the measure should calculate the working days based on the date field in table_C without considering the tracked activities. Having this output:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| process_working_activity | countrows_working_day_germany |
|---------------------------|-------------------------------|
| AA                        | 22                            |
| BB                        | 22                            |
| CC                        | 22                            |&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;Do you have any ideas how to perform this (independent) calculation? Thank you in advance &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2023 17:31:36 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/how-to-replicate-a-specific-tableau-measure-in-power-bi-using/m-p/3580319#M138083</guid>
      <dc:creator>simon_pbi_92</dc:creator>
      <dc:date>2023-12-12T17:31:36Z</dc:date>
    </item>
  </channel>
</rss>

