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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

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.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

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.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors