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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
PowPow
Frequent Visitor

Snapshot open and due days

Hi everyone,

i'm trying to figure out if i can replace our daily snapshot table by using dax measures directly on top of the transactional table. It was easy to calculate the balance but i am having trouble calculating Open and Due days.

 

First of all here is the end goal based on the snapshot data for one document. In the end scenario the users would be able to filter this also on customers, aging buckets etc.

AR.PNG

For reference, this is how a part of the snapshot table looks like for this particular document:

snapshot tablesnapshot table

And this is the transactional table for that same document:

transactionaltransactional

The data model with transactional table and just the date table:

model.PNG

 

The Balance measure works perfectly with the formula:

Receivables Balance :=
IF (
    MIN ( 'Calendar'[DateSK] )
        <= CALCULATE ( MAX ( Receivables[PostingDateSK] ); ALL ( Receivables ) );
    CALCULATE (
        SUM ( Receivables[Amount (LCY)] );
        USERELATIONSHIP ( Receivables[DetailedLedgerPostingDateSK]; 'Calendar'[DateSK] );
        FILTER (
            ALL ( 'Calendar'[DateActual] );
            'Calendar'[DateActual] <= MAX ( 'Calendar'[DateActual] )
        )
    )
)

Like i said i am struggling with open days and due days measure calculation. Open days should show the number of days between the displayed date and the posting date. Due days should show the difference between the displayed date and due date. Negative is before due, positive is due. And the measures should both aggregate as averages.

 

I've checked several posts but i couldn't get any of the proposed solutions working.

 

Thanks in advance, any ideas would be appreciated.

 

 

1 ACCEPTED SOLUTION
v-ljerr-msft
Employee
Employee

Hi @PowPow,

 

Have you tried using SUMX Function (DAX) and DATEDIFF Function (DAX) to calculate open and due days in this scenario? The formula below is for your reference.

Open Days :=
VAR maxDate =
    MAX ( 'Calendar'[DateActual] )
RETURN
    IF (
        MIN ( 'Calendar'[DateSK] )
            <= CALCULATE ( MAX ( Receivables[PostingDateSK] ); ALL ( Receivables ) );
        CALCULATE (
            SUMX ( Receivables; DATEDIFF ( maxDate; Receivables[PostingDate]; DAY ) );
            USERELATIONSHIP ( Receivables[DetailedLedgerPostingDateSK]; 'Calendar'[DateSK] );
            FILTER ( ALL ( 'Calendar'[DateActual] ); 'Calendar'[DateActual] <= maxDate )
        )
    )
Due Days :=
VAR maxDate =
    MAX ( 'Calendar'[DateActual] )
RETURN
    IF (
        MIN ( 'Calendar'[DateSK] )
            <= CALCULATE ( MAX ( Receivables[PostingDateSK] ); ALL ( Receivables ) );
        CALCULATE (
            SUMX (
                Receivables;
                IF (
                    Receivables[DueDate] > maxDate;
                    DATEDIFF ( maxDate; Receivables[DueDate]; DAY );
                    DATEDIFF ( Receivables[DueDate]; maxDate; DAY )
                )
            );
            USERELATIONSHIP ( Receivables[DetailedLedgerPostingDateSK]; 'Calendar'[DateSK] );
            FILTER ( ALL ( 'Calendar'[DateActual] ); 'Calendar'[DateActual] <= maxDate )
        )
    )

 

Regards

View solution in original post

2 REPLIES 2
v-ljerr-msft
Employee
Employee

Hi @PowPow,

 

Have you tried using SUMX Function (DAX) and DATEDIFF Function (DAX) to calculate open and due days in this scenario? The formula below is for your reference.

Open Days :=
VAR maxDate =
    MAX ( 'Calendar'[DateActual] )
RETURN
    IF (
        MIN ( 'Calendar'[DateSK] )
            <= CALCULATE ( MAX ( Receivables[PostingDateSK] ); ALL ( Receivables ) );
        CALCULATE (
            SUMX ( Receivables; DATEDIFF ( maxDate; Receivables[PostingDate]; DAY ) );
            USERELATIONSHIP ( Receivables[DetailedLedgerPostingDateSK]; 'Calendar'[DateSK] );
            FILTER ( ALL ( 'Calendar'[DateActual] ); 'Calendar'[DateActual] <= maxDate )
        )
    )
Due Days :=
VAR maxDate =
    MAX ( 'Calendar'[DateActual] )
RETURN
    IF (
        MIN ( 'Calendar'[DateSK] )
            <= CALCULATE ( MAX ( Receivables[PostingDateSK] ); ALL ( Receivables ) );
        CALCULATE (
            SUMX (
                Receivables;
                IF (
                    Receivables[DueDate] > maxDate;
                    DATEDIFF ( maxDate; Receivables[DueDate]; DAY );
                    DATEDIFF ( Receivables[DueDate]; maxDate; DAY )
                )
            );
            USERELATIONSHIP ( Receivables[DetailedLedgerPostingDateSK]; 'Calendar'[DateSK] );
            FILTER ( ALL ( 'Calendar'[DateActual] ); 'Calendar'[DateActual] <= maxDate )
        )
    )

 

Regards

Hi @v-ljerr-msft,

 

of course, variables! Thank you very much for this, it helps a lot! I will have to limit the calculations to just count the days when the transaction is still open/due but that should be straitghtforward.

 

Thanks again!

Best,

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.