Forum Discussion

MoreDataPlease's avatar
MoreDataPlease
Frequent Visitor
9 years ago
Solved

Dynamic Column Count Based on Date Slicer Selection

I have a claims history table with multiple rows for each claim number.  Each row provides the claim number, the status of the claim, and a date when that status occurred.  I'm trying to count the number of claims that are currently open/reopened based on a date slicer the user can control.  A simple view of my data:

       

Claim NumberStatusDateRank
123Open7/26/20161
123Close11/7/20162
123Reopened1/23/20173
123Closed2/21/20174
456Open1/25/20171
456Closed3/1/20172

 

I added a rank column thinking it might help me select the max rank as of a given date, which could then be linked to the status but I haven't been able to figure out how to do that.  

 

What I am trying to get at :

given the data in the above table if a user selected via a slicer (DimDate[Date] serves as the field for the slicer) the following dates, I would return the following number of claims.

On Date# of Open Claims
8/1/20161
12/1/20160
1/25/20172
2/27/20171

 

Any help on creating the measure for this would be greatly appreciated. 

  • Here's my thought on how to tackle this.  I created your table in Excel and imported it into PBI, then did the following:

     

    • Created a date table
      DateTable = Calendar(Minx(table1,Table1[Date]),Now()) 
       
    • To the date table I added 3 calculated columns, purpose being to count how many claims have been opened, reopened, and closed all time as of that date:
    • AllTimeOpened = CALCULATE(
          COUNTROWS(Table1),
          FILTER(Table1,
              DateTable[Date] >= Table1[Date] &&
              Table1[Status] = "Open")
      )
      AllTimeReopened = CALCULATE(
          COUNTROWS(Table1),
          FILTER(Table1,
              DateTable[Date] >= Table1[Date] &&
              Table1[Status] = "Reopened")
      )
      AllTimeClosed = CALCULATE(
          COUNTROWS(Table1),
          FILTER(Table1,
              DateTable[Date] >= Table1[Date] &&
              Table1[Status] = "Closed")
      )
    • Then to the date table, I added another calculated column called "Open Cases"
    • Open Cases = CALCULATE(
          VALUES(DateTable[AllTimeOpened]) +
          VALUES(DateTable[AllTimeReopened]) -
          VALUES(DateTable[AllTimeClosed] )
      )

    The result of all this is that I have a count in my date table of how many actively open cases there are on any given day.  I can chart this out, but if I try to make a card/slicer it gives me inaccurate data because it sums up my column.  Instead I probably want to make it a calculated measure instead.  The measure will only be meaningful if a date slicer is used, so I wrote it as such:

     

    Open Measure = IFERROR(
    	CALCULATE(
        VALUES(DateTable[AllTimeOpened]) +
        VALUES(DateTable[AllTimeReopened]) -
        VALUES(DateTable[AllTimeClosed] )
    	),
    	"Use Slicer")

    Might be a better way to do that.

     

    Anyway, here are the visual results:

     

     

     

    Is this on the right path of what you're looking for?

     

    Dan

9 Replies

  • Here's my thought on how to tackle this.  I created your table in Excel and imported it into PBI, then did the following:

     

    • Created a date table
      DateTable = Calendar(Minx(table1,Table1[Date]),Now()) 
       
    • To the date table I added 3 calculated columns, purpose being to count how many claims have been opened, reopened, and closed all time as of that date:
    • AllTimeOpened = CALCULATE(
          COUNTROWS(Table1),
          FILTER(Table1,
              DateTable[Date] >= Table1[Date] &&
              Table1[Status] = "Open")
      )
      AllTimeReopened = CALCULATE(
          COUNTROWS(Table1),
          FILTER(Table1,
              DateTable[Date] >= Table1[Date] &&
              Table1[Status] = "Reopened")
      )
      AllTimeClosed = CALCULATE(
          COUNTROWS(Table1),
          FILTER(Table1,
              DateTable[Date] >= Table1[Date] &&
              Table1[Status] = "Closed")
      )
    • Then to the date table, I added another calculated column called "Open Cases"
    • Open Cases = CALCULATE(
          VALUES(DateTable[AllTimeOpened]) +
          VALUES(DateTable[AllTimeReopened]) -
          VALUES(DateTable[AllTimeClosed] )
      )

    The result of all this is that I have a count in my date table of how many actively open cases there are on any given day.  I can chart this out, but if I try to make a card/slicer it gives me inaccurate data because it sums up my column.  Instead I probably want to make it a calculated measure instead.  The measure will only be meaningful if a date slicer is used, so I wrote it as such:

     

    Open Measure = IFERROR(
    	CALCULATE(
        VALUES(DateTable[AllTimeOpened]) +
        VALUES(DateTable[AllTimeReopened]) -
        VALUES(DateTable[AllTimeClosed] )
    	),
    	"Use Slicer")

    Might be a better way to do that.

     

    Anyway, here are the visual results:

     

     

     

    Is this on the right path of what you're looking for?

     

    Dan

    • MoreDataPlease's avatar
      MoreDataPlease
      Frequent Visitor

      danrmcallister Thank you for the response!  Appears this should get me what I need.  Putting it in now to test.  Will let you know final verdict.

    • MoreDataPlease's avatar
      MoreDataPlease
      Frequent Visitor

      danrmcallister I'm running into an error with trying to create the measure - it's telling me that the syntax is incorrect.  Any ideas on why I might be getting that error?

       

      My Measure in the Date Table:

      Open Measure = CALCULATE(
           VALUES(Date[AllTimeOpened])+
           VALUES('Date'[AllTimeReopened]) -
           VALUES('Date'[AllTimeClosed]))

       

      ERROR:

      The syntax for '[AllTimeOpened]' is incorrect. (DAX(CALCULATE( VALUES(Date[AllTimeOpened])+ VALUES('Date'[AllTimeReopened]) - VALUES('Date'[AllTimeClosed])))).

      • danrmcallister's avatar
        danrmcallister
        Resolver II

        The "AllTimeOpened", "AllTimeReopened", and "AllTimeClosed" fields you see below were calculated columns I created against my date table.  Did you complete that step first?