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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
user_dil
Frequent Visitor

Dax measure to dynamically Calculate the Gross Total

Hi All,

Currently, I'm facing some trouble while trying to calculate the gross total in my Transactions Table. What I want is to calculate the gross total for each product based on the unit price. But when the unit price gets updated, only the invoices issued on or after the unit price is updated should have the updated unit price for gross total calculation and older records should remain with the older unit price.

For example;

Product code 113 unit price is updated on 3/06/2022, so for the gross total calculation unit price should be $2 for invoices issued before 3/06/2022 and $2.5 for invoices issued on or after 3/06/2022. This should dynamically change as well if the unit price is updated again.

 

Here are the two tables; Transactions and Product Pricing. Thanks in Advance!

Transactions

Invoice noInvoice DateProduct codeProduct QtyGross Total
00122/06/20221135 
00132/06/20221143 
00142/06/20221127 
00153/06/202211212 
00163/06/20221106 
00173/06/20221153 
00184/06/20221139 
00194/06/202211515 
00204/06/20221104 

 

Product Pricing:

Product codeUnit Price ($)Date updatedActive Flag
11034/04/20221
11244/04/20221
11325/05/20220
1132.53/06/20221
1143.52/04/20221
11532/04/20221

 

Thanks in Advance!

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Picture1.png

 

Qty measure: = 
SUM( Transactions[Product Qty] )

 

Price per product measure: = 
VAR _currentdate =
    MAX ( 'Calendar'[Date] )
VAR _lastnonblankdateinpricetable =
    MAXX (
        FILTER ( 'Product Pricing', 'Product Pricing'[Date updated] <= _currentdate ),
        'Product Pricing'[Date updated]
    )
RETURN
    IF (
        [Qty measure:] <> BLANK (),
        MAXX (
            FILTER (
                'Product Pricing',
                'Product Pricing'[Date updated] = _lastnonblankdateinpricetable
            ),
            'Product Pricing'[Unit Price ($)]
        )
    )

 

Gross total measure: = 
SUMX (
    SUMMARIZE (
        Transactions,
        'Product'[Product code],
        'Calendar'[Date],
        Transactions[Invoice no]
    ),
    [Qty measure:] * [Price per product measure:]
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

1 REPLY 1
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Picture1.png

 

Qty measure: = 
SUM( Transactions[Product Qty] )

 

Price per product measure: = 
VAR _currentdate =
    MAX ( 'Calendar'[Date] )
VAR _lastnonblankdateinpricetable =
    MAXX (
        FILTER ( 'Product Pricing', 'Product Pricing'[Date updated] <= _currentdate ),
        'Product Pricing'[Date updated]
    )
RETURN
    IF (
        [Qty measure:] <> BLANK (),
        MAXX (
            FILTER (
                'Product Pricing',
                'Product Pricing'[Date updated] = _lastnonblankdateinpricetable
            ),
            'Product Pricing'[Unit Price ($)]
        )
    )

 

Gross total measure: = 
SUMX (
    SUMMARIZE (
        Transactions,
        'Product'[Product code],
        'Calendar'[Date],
        Transactions[Invoice no]
    ),
    [Qty measure:] * [Price per product measure:]
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.