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
mmace1
Impactful Individual
Impactful Individual

Using an Audit Table to show the state of things at an arbitrary point in time? I have no idea.

Hi,

 

At my company, we have customers, who in turn have vendors who accept various forms of payment.  Summarizing say, right now, how many of a customer's vendors accept <X> form of payment, is easy.

 

Here's a look at a modified/truncated version of the table we'd use for that.  The Payment Type column has the data we're looking for.

 

VendorListIDCustomerNumberVendorIdForeignIdNameAddressLine1MiDPayment Type
3055021665-004EDE60B3C-7E89-4COG275Example name 1Address 1DE15CFC4-7827-41212
3055020665-00429146617-E12B-4CEN036Example name 2Address 22B77CA02-1999-41212
3055019665-004E7A8D372-805F-4CBS100Example name 3Address 3F241B631-5BCD-41212
3055018665-004D6D4D794-5E70-4BER100Example name 4Address 49E0E7251-C0BE-41212
3055017665-004ABFED05D-286C-4ADV038Example name 5Address 58E6CDFCA-2FA7-41212
3055016928-00737E90AE7-56D0-4628703Example name 6Address 6C1B761E7-79F4-41212
3055015928-0074E6C6E20-21BB-4215823Example name 7Address 78798A7B8-5752-41212
3055014928-007352F97B5-242A-415660Example name 8Address 8059B2F66-9B94-41212
3055013928-007A6D2E12A-4DA5-415563Example name 9Address 9F6DCCD9A-7410-41212
3055012928-007EBFB1E08-CA41-415506Example name 10Address 1073C07C79-F258-41212

 

 

But then, what if we wanted to see say - a week ago, what was the status of all of our customer's suppliers?   How has it changed since last week?  Since 2 weeks ago?   Well, we have an audit table that adds an entry every time payment status changes:

 

VendorListPaymentTypeChangeAuditIDVendorIdMasterVendorIDPaymentTypeCreateDateUTC
59752591472C3D5-8A7F-4C216849C-081D-46129/13/2017 1:46
59752571472C3D5-8A7F-4C216849C-081D-46129/13/2017 1:44
59711111472C3D5-8A7F-4C216849C-081D-46129/12/2017 20:23
59711091472C3D5-8A7F-4C216849C-081D-46129/12/2017 20:23
59378531472C3D5-8A7F-4C216849C-081D-410609/11/2017 14:26
59187801472C3D5-8A7F-4C216849C-081D-410609/7/2017 13:26
59187721472C3D5-8A7F-4C216849C-081D-410609/7/2017 13:23
58430051472C3D5-8A7F-4C216849C-081D-410608/29/2017 14:12
47604841472C3D5-8A7F-4C216849C-081D-410603/24/2017 17:31
41780811472C3D5-8A7F-4C216849C-081D-461212/7/2016 21:11

 

 

You can connect the two via the VendorID (amongst other things). A manual check is easy enough. 

 

But, how to automate this?  The CustomerTtable - AuditTtable is a one-to-many relationship...not to mention, we're not looking to pull a single piece of data over from the audit table, but rather check...was the entry for vendor <X> any different 1 week ago, 2 weeks ago?  etc.

 

I fundamentally don't understand how to do this, but to conserve space, I'm guessing audit tables arranged like the above, are typical.  Can anyone point me in a direction to look?

 

Thanks!

 

 

1 ACCEPTED SOLUTION
v-ljerr-msft
Employee
Employee

Hi @mmace1,

 

If I understand you correctly, you should be able to use the formula below to create a new calculate column in CustomerT table to get the Payment Type last week for Vendor<X>. Smiley Happy

Payment Type Last Week = 
VAR currentVendorId = CustomerT[VendorId]
VAR currentDate =
    CALCULATE (
        MAX ( AuditT[CreateDateUTC] ),
        FILTER ( AuditT, AuditT[VendorId] = currentVendorId )
    )
VAR lastCreateDate =
    CALCULATE (
        MAX ( AuditT[CreateDateUTC] ),
        FILTER (
            AuditT,
            AuditT[CreateDateUTC]
                <= currentDate - 6
                && AuditT[VendorId] = currentVendorId
        )
    )
RETURN
    CALCULATE (
        MAX ( AuditT[PaymentType] ),
        FILTER (
            AuditT,
            AuditT[CreateDateUTC] = lastCreateDate
                && AuditT[VendorId] = currentVendorId
        )
    )

And the Payment Type two weeks ago.

Payment Type Two Weeks ago = 
VAR currentVendorId = CustomerT[VendorId]
VAR currentDate =
    CALCULATE (
        MAX ( AuditT[CreateDateUTC] ),
        FILTER ( AuditT, AuditT[VendorId] = currentVendorId )
    )
VAR lastCreateDate =
    CALCULATE (
        MAX ( AuditT[CreateDateUTC] ),
        FILTER (
            AuditT,
            AuditT[CreateDateUTC]
                <= currentDate - 13
                && AuditT[VendorId] = currentVendorId
        )
    )
RETURN
    CALCULATE (
        MAX ( AuditT[PaymentType] ),
        FILTER (
            AuditT,
            AuditT[CreateDateUTC] = lastCreateDate
                && AuditT[VendorId] = currentVendorId
        )
    )

c2.PNG

 

Regards

View solution in original post

2 REPLIES 2
v-ljerr-msft
Employee
Employee

Hi @mmace1,

 

If I understand you correctly, you should be able to use the formula below to create a new calculate column in CustomerT table to get the Payment Type last week for Vendor<X>. Smiley Happy

Payment Type Last Week = 
VAR currentVendorId = CustomerT[VendorId]
VAR currentDate =
    CALCULATE (
        MAX ( AuditT[CreateDateUTC] ),
        FILTER ( AuditT, AuditT[VendorId] = currentVendorId )
    )
VAR lastCreateDate =
    CALCULATE (
        MAX ( AuditT[CreateDateUTC] ),
        FILTER (
            AuditT,
            AuditT[CreateDateUTC]
                <= currentDate - 6
                && AuditT[VendorId] = currentVendorId
        )
    )
RETURN
    CALCULATE (
        MAX ( AuditT[PaymentType] ),
        FILTER (
            AuditT,
            AuditT[CreateDateUTC] = lastCreateDate
                && AuditT[VendorId] = currentVendorId
        )
    )

And the Payment Type two weeks ago.

Payment Type Two Weeks ago = 
VAR currentVendorId = CustomerT[VendorId]
VAR currentDate =
    CALCULATE (
        MAX ( AuditT[CreateDateUTC] ),
        FILTER ( AuditT, AuditT[VendorId] = currentVendorId )
    )
VAR lastCreateDate =
    CALCULATE (
        MAX ( AuditT[CreateDateUTC] ),
        FILTER (
            AuditT,
            AuditT[CreateDateUTC]
                <= currentDate - 13
                && AuditT[VendorId] = currentVendorId
        )
    )
RETURN
    CALCULATE (
        MAX ( AuditT[PaymentType] ),
        FILTER (
            AuditT,
            AuditT[CreateDateUTC] = lastCreateDate
                && AuditT[VendorId] = currentVendorId
        )
    )

c2.PNG

 

Regards

mmace1
Impactful Individual
Impactful Individual

Wow...that's not that long of a formula, yet I don't understand it yet.  It seems to work though, thanks!

 

 

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.