Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
AbbyLear
Frequent Visitor

Measure for average DSO within a category

Hi guys, 

 

I have a table that has the following fields.

 

AbbyLear_0-1657911207891.png

 

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: 

AbbyLear_1-1657911297631.png

 

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! 

 

1 ACCEPTED SOLUTION

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 ) )

 

View solution in original post

7 REPLIES 7
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])

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 ) )

 

Great. thanks for the help! 

Ashish_Mathur
Super User
Super User

Hi,

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


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
lbendlin
Super User
Super User

Please provide sanitized sample data that fully covers your issue. If you paste the data into a table in your post or use one of the file services it will be easier to assist you. I cannot use screenshots of your source data.

Please show the expected outcome based on the sample data you provided. Screenshots of the expected outcome are ok.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

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

Hi,

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


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.