<?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 Count how many times a distinct case has been in a certain state (multiple rows per case) in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-how-many-times-a-distinct-case-has-been-in-a-certain-state/m-p/4268865#M169269</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Im new to PowerBI and are really stuck with an issue. I have a data sample size of 37.000 rows with cases. These cases have been in mulitple states through out their resolve time. I need to calculat how many times each case has been in a state, if its been in a state multiple times and how longe the case has been in the differnet states.&amp;nbsp;&lt;BR /&gt;Here is a example of my data:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried mulitple columnes calculations but nothing seams to give me the result i want.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 04 Nov 2024 09:04:45 GMT</pubDate>
    <dc:creator>CharliBrown</dc:creator>
    <dc:date>2024-11-04T09:04:45Z</dc:date>
    <item>
      <title>Count how many times a distinct case has been in a certain state (multiple rows per case)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-how-many-times-a-distinct-case-has-been-in-a-certain-state/m-p/4268865#M169269</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Im new to PowerBI and are really stuck with an issue. I have a data sample size of 37.000 rows with cases. These cases have been in mulitple states through out their resolve time. I need to calculat how many times each case has been in a state, if its been in a state multiple times and how longe the case has been in the differnet states.&amp;nbsp;&lt;BR /&gt;Here is a example of my data:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried mulitple columnes calculations but nothing seams to give me the result i want.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Nov 2024 09:04:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-how-many-times-a-distinct-case-has-been-in-a-certain-state/m-p/4268865#M169269</guid>
      <dc:creator>CharliBrown</dc:creator>
      <dc:date>2024-11-04T09:04:45Z</dc:date>
    </item>
    <item>
      <title>Re: Count how many times a distinct case has been in a certain state (multiple rows per case)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-how-many-times-a-distinct-case-has-been-in-a-certain-state/m-p/4268887#M169272</link>
      <description>&lt;P&gt;To analyze this data in Power BI, you can use DAX to calculate both the count of state transitions and the total time spent in each state for each case. Here’s a step-by-step guide to help you set it up.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Step 1&lt;/STRONG&gt;: Import Data into Power BI&lt;BR /&gt;1. Load your data into Power BI by going to Home &amp;gt; Get Data and selecting your data source (Excel, CSV, etc.).&lt;/P&gt;&lt;P&gt;Step 2: Calculate the Number of Times Each Case has been in a State&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;1. Create a Measure to Count State Occurrences:&lt;/STRONG&gt; Use a DAX measure to count the number of occurrences each case has been in a specific state.&lt;/P&gt;&lt;P&gt;DAX&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;StateCount =
COUNTROWS(FILTER(
TableName,
TableName[Case Number] = EARLIER(TableName[Case Number]) &amp;amp;&amp;amp;
TableName[State] = EARLIER(TableName[State])
))&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Replace `TableName` with the actual name of your table in Power BI.&lt;/P&gt;&lt;P&gt;2. &lt;STRONG&gt;Add StateCount to a Visual:&lt;/STRONG&gt; Use a table or matrix visual in Power BI, with &lt;STRONG&gt;Case Number&lt;/STRONG&gt;&amp;nbsp;and &lt;STRONG&gt;State&lt;/STRONG&gt; on rows, and the &lt;STRONG&gt;StateCount&lt;/STRONG&gt; measure as values. This will display the number of times each case has entered each state.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;Step 3&lt;/STRONG&gt;: Calculate the Total Time in Each State for Each Case&lt;BR /&gt;1. &lt;STRONG&gt;Add a Column for Time in State&lt;/STRONG&gt;: Use DAX to create a calculated column that calculates the duration of time each case has spent in a particular state. We can use the &lt;STRONG&gt;Start&lt;/STRONG&gt;&amp;nbsp;and &lt;STRONG&gt;End&lt;/STRONG&gt;&amp;nbsp;columns for this.&lt;/P&gt;&lt;P&gt;DAX&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;TimeInState =
DATEDIFF(
TableName[Start],
TableName[End],
MINUTE
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This will give you the time spent in each state in minutes. You can change `MINUTE` to `HOUR` or `DAY` if a different time unit is needed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. &lt;STRONG&gt;Create a Measure to Sum Time in State&lt;/STRONG&gt;: If you want to see the total time spent in each state for each case, create a measure that sums the `TimeInState` column:&lt;/P&gt;&lt;P&gt;DAX&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;TotalTimeInState =
CALCULATE(
SUM(TableName[TimeInState]),
ALLEXCEPT(TableName, TableName[Case Number], TableName[State])
)&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;3. &lt;STRONG&gt;Add TotalTimeInState to a Visual:&lt;/STRONG&gt; Use this measure in a table or matrix visual along with &lt;STRONG&gt;Case Number&lt;/STRONG&gt;&amp;nbsp;and &lt;STRONG&gt;State&lt;/STRONG&gt; to show the total time spent in each state for each case.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Step 4: Analyze Results&lt;/STRONG&gt;&lt;BR /&gt;- You can create visuals like Bar Charts or Pie Charts to display the distribution of time spent across states or the frequency of state transitions.&lt;BR /&gt;- Filter the visuals by Case Number to analyze individual cases or by State to focus on specific states across cases.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Nov 2024 09:22:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-how-many-times-a-distinct-case-has-been-in-a-certain-state/m-p/4268887#M169272</guid>
      <dc:creator>FarhanJeelani</dc:creator>
      <dc:date>2024-11-04T09:22:37Z</dc:date>
    </item>
    <item>
      <title>Re: Count how many times a distinct case has been in a certain state (multiple rows per case)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-how-many-times-a-distinct-case-has-been-in-a-certain-state/m-p/4269884#M169319</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="836002" data-lia-user-login="CharliBrown" class="lia-mention lia-mention-user"&gt;CharliBrown&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&amp;nbsp;FarhanJeelani&amp;nbsp; for sharing the method. I created some sample data based on your description and attached it to hopefully better help you with your problem.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Here is the data I created:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Create a calculated column:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;StateCount = COUNTROWS(FILTER('Table', 'Table'[State] = EARLIER('Table'[State]) &amp;amp;&amp;amp; 'Table'[Case Number] = EARLIER('Table'[Case Number])))&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;TotalTime =
VAR _duration = DATEDIFF('Table'[Start Time],'Table'[End Time],HOUR)
RETURN
_duration&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Column =
CALCULATE(SUM('Table'[TotalTime]),FILTER('Table','Table'[Case Number] = EARLIER('Table'[Case Number]) &amp;amp;&amp;amp; 'Table'[State] = EARLIER('Table'[State])))&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The final result is shown below:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this is not the result you wish to get. Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.&amp;nbsp;We can better understand the problem and help you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Clara Gong&lt;/P&gt;
&lt;P&gt;If there is any post&amp;nbsp;&lt;STRONG&gt;&lt;I&gt;helps&lt;/I&gt;&lt;/STRONG&gt;, then please consider&amp;nbsp;&lt;STRONG&gt;&lt;I&gt;Accept it as the solution&lt;/I&gt;&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;to help the other members find it more quickly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2024 02:11:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-how-many-times-a-distinct-case-has-been-in-a-certain-state/m-p/4269884#M169319</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-11-05T02:11:26Z</dc:date>
    </item>
  </channel>
</rss>

