Forum Discussion

AbbyLear's avatar
AbbyLear
Frequent Visitor
4 years ago
Solved

Measure for average DSO within a category

Hi guys, 

 

I have a table that has the following fields.

 

 

Each row is a certain activity associated with the case (could be a "charge" or a payment received"). Case date and payer is unique to each case ID. 

 

I'm trying to create a measure called "DSO" (days sales outstanding) which calculates the days between the case date and the first payment date for each case. Then I want to run some visuals that shows the average per case DSO for each payer, each quarter at the case ID level. 

 

For example, I want to be able to create a Matrix in PowerBI with the following information: 

 

For the first row here, 23.5 is arrived as the average DSO for case #1 (19) and #2 (28). 

 

I was able to get DSO by doing a simple "Datediff" formula. However, not sure how to get it to calculate the average per case by payer and by quarter? Any help would be appreciated! 

 

Thanks! 

 

  • That's pretty close to what I was about to propose as a measure:

     

    DSO = 
    var a = VALUES('Table'[Case ID])
    var b = ADDCOLUMNS(a,"Charge Date",var c=[Case ID] return CALCULATE(min('Table'[Case Date]),'Table'[Case ID]=c,'Table'[Type]="Charge"))
    var c = ADDCOLUMNS(b,"First Payment",var c=[Case ID] return CALCULATE(min('Table'[Payment Date]),'Table'[Case ID]=c,'Table'[Type]="Payment"))
    return averagex(c,DATEDIFF([Charge Date],[First Payment],DAY))

    or slightly more readable

    DSO =
    VAR b =
        ADDCOLUMNS (
            VALUES ( 'Table'[Case ID] ),
            "Charge Date",
                CALCULATE (
                    MIN ( 'Table'[Case Date] ),
                    ALLEXCEPT ( 'Table', 'Table'[Case ID] ),
                    'Table'[Type] = "Charge"
                ),
            "First Payment",
                CALCULATE (
                    MIN ( 'Table'[Payment Date] ),
                    ALLEXCEPT ( 'Table', 'Table'[Case ID] ),
                    'Table'[Type] = "Payment"
                )
        )
    RETURN
        AVERAGEX ( b, DATEDIFF ( [Charge Date], [First Payment], DAY ) )

     

7 Replies

    • AbbyLear's avatar
      AbbyLear
      Frequent Visitor

      Thanks! I followed the tutorial and pasted the data below. Let me know if this doesn't work! 

       

      Case IDPayerCase DateCase QuarterTypeTxIDPayment DatePayment$Charge$
      1Aetna1/1/20212021 Q1Charge1nullnull$200
      1Aetna1/1/20212021 Q1Payment21/20/2021$10 
      1Aetna1/1/20212021 Q1Payment31/31/2021$20 
      2Aetna2/1/20212021 Q1Charge4nullnull$400
      2Aetna2/1/20212021 Q1Payment53/1/2021$200 
      2Aetna2/1/20212021 Q1Payment64/1/2021$100 
      2Aetna2/1/20212021 Q1Payment75/1/2021$50 
      3Cigna4/1/20212021 Q2Charge8nullnull$300
      3Cigna4/1/20212021 Q2Payment94/25/2021$100 
      4Aetna5/1/20212021 Q2Charge10nullnull$1,000
      4Aetna5/1/20212021 Q2Payment115/15/2021$200 
      4Aetna5/1/20212021 Q2Payment125/30/2021$300 
      4Aetna5/1/20212021 Q2Payment136/30/2021$400 
              

       

       

       

      expected outcome:

       

      PayerCase QuarterDSO
      Aetna2021 Q123.5
      Aetna2021 Q214
      Cigna2021 Q124
      • Ashish_Mathur's avatar
        Ashish_Mathur
        Icon for Super User rankSuper User

        Hi,

        How did you arrive at the 19 and 28.  Please show those calculations in an MS Excel file.

  • Hi,

    Share the link from where i can download your PBI file.  Ensure that your DSO measure is already written there.

  • AbbyLear's avatar
    AbbyLear
    Frequent Visitor

    So I sort of figured this out today by doing the following. If anyone has a better/more efficient way to do this - let me know. 

     

    1. Create a calculated column for # days between Payment date and Case Date

    2. Create a measure called "Min DSO" = calculate(min([DSO]),ALLEXCEPT(Table,Table[Case ID]))

    3. Create a measure called "Avg DSO" = AVERAGEX(values(Table[Case ID]),[Min DSO])

    • lbendlin's avatar
      lbendlin
      Icon for Super User rankSuper User

      That's pretty close to what I was about to propose as a measure:

       

      DSO = 
      var a = VALUES('Table'[Case ID])
      var b = ADDCOLUMNS(a,"Charge Date",var c=[Case ID] return CALCULATE(min('Table'[Case Date]),'Table'[Case ID]=c,'Table'[Type]="Charge"))
      var c = ADDCOLUMNS(b,"First Payment",var c=[Case ID] return CALCULATE(min('Table'[Payment Date]),'Table'[Case ID]=c,'Table'[Type]="Payment"))
      return averagex(c,DATEDIFF([Charge Date],[First Payment],DAY))

      or slightly more readable

      DSO =
      VAR b =
          ADDCOLUMNS (
              VALUES ( 'Table'[Case ID] ),
              "Charge Date",
                  CALCULATE (
                      MIN ( 'Table'[Case Date] ),
                      ALLEXCEPT ( 'Table', 'Table'[Case ID] ),
                      'Table'[Type] = "Charge"
                  ),
              "First Payment",
                  CALCULATE (
                      MIN ( 'Table'[Payment Date] ),
                      ALLEXCEPT ( 'Table', 'Table'[Case ID] ),
                      'Table'[Type] = "Payment"
                  )
          )
      RETURN
          AVERAGEX ( b, DATEDIFF ( [Charge Date], [First Payment], DAY ) )