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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
ThangNT
Helper I
Helper I

How to Calculate TTM Purchase Involving Date from Two Tables Balance Sheet and Income Statement

I want to calculate Purchase based on the formula Purchase = Ending Inventory - Beginning Inventory + COGS và TTM Purchase. I have written some DAX formula as follows:
Beginning Inventories =
CALCULATE(
[Ending Inventories],
PREVIOUSQUARTER('Date'[Date Key])
)
Ending Inventories =
CALCULATE(
[BalanceSheetValues],
Accounts[Account] = "Inventories"
)
COGS =
CALCULATE(
[QuarterlyIncomeStatementValues],
Accounts[SubAccount] = "Cost of Goods Sold"
) * -1
Purchase = Ending Inventories - Beginning = COGS
TTM Purchase =
CALCULATE(
SUMX(
IncomeStatement,
[Purchase]
),
DATESINPERIOD(
'Date'[Date Key],
Max('Date'[Date Key]),
-4,
QUARTER
),
FILTER(
All('Date'),
Max('Date'[Date Key]) > Date(2015,9,30)
)
)

I've identified the issue: the Purchase measure refers to two tables, BalanceSheet and IncomeStatement, while the SUMX function only operates over a single table. As a result, when I use the SUMX function to iterate over the IncomeStatement, the value of TTM Purchase ends up being the same as the value of TTM COGS. However, I'm still struggling to find a solution.

https://www.dropbox.com/scl/fi/ib8wnknxpglr7dfrfzjrr/NFC_Company-Analysis.pbix?rlkey=f50uf91t9oih7rt...
The below table shows the values that I expect to calculate.

ThangNT_0-1727864415103.png

 

1 ACCEPTED SOLUTION

Hi @ThangNT ,

 

 I think your issue should be caused that the Date table is not continuous. Here I suggest you to update your meausre as below.

Beginning Inventories =
CALCULATE (
    [Ending Inventories],
    FILTER ( ALLSELECTED ( 'Date' ), 'Date'[Column] = MAX ( 'Date'[Column] ) - 1 )
)
TTM Beginning Inventory =
IF (
    MAX ( 'Date'[Date Key] ) > DATE ( 2015, 9, 30 ),
    SUMX (
        FILTER (
            ALLSELECTED ( 'Date' ),
            'Date'[Column] <= MAX ( 'Date'[Column] )
                && 'Date'[Column]
                    >= MAX ( 'Date'[Column] ) - 4
        ),
        [Beginning Inventories]
    )
)

Result is as below.

vrzhoumsft_0-1727925604990.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

3 REPLIES 3
ThangNT
Helper I
Helper I

I attempted a different approach to calculate TTM Purchase using the formula: TTM Ending Inventory - TTM Beginning Inventory + TTM COGS. The formulas for TTM Ending Inventory and TTM COGS work perfectly, but the formula for TTM Beginning Inventory does not return the correct values. I've tried various formulas as follows:
TTM Beginning Inventory =
SUMX(BalanceSheet, [Beginning Inventories])
It shows no values.

TTM Beginning Inventories =
CALCULATE(
[Ending Inventories],
FILTER(
ALL('Date'),
'Date'[Date Key] < MIN('Date'[Date Key])
)
)
It shows cumulative Beginning Inventories from 2014/12/31.

TTM Beginning Inventory =
CALCULATE(
[Beginning Inventories],
DATESINPERIOD(
'Date'[Date Key],
MAX('Date'[Date Key]),
-4,
QUARTER
),
FILTER(
ALl('Date'),
MAX('Date'[Date Key]) > Date(2015,9,30)
)
)

TTM Beginning Inventories at 2015/12/31 is equal to Beginning Inventories at 2014/12/31

Hi @ThangNT ,

 

 I think your issue should be caused that the Date table is not continuous. Here I suggest you to update your meausre as below.

Beginning Inventories =
CALCULATE (
    [Ending Inventories],
    FILTER ( ALLSELECTED ( 'Date' ), 'Date'[Column] = MAX ( 'Date'[Column] ) - 1 )
)
TTM Beginning Inventory =
IF (
    MAX ( 'Date'[Date Key] ) > DATE ( 2015, 9, 30 ),
    SUMX (
        FILTER (
            ALLSELECTED ( 'Date' ),
            'Date'[Column] <= MAX ( 'Date'[Column] )
                && 'Date'[Column]
                    >= MAX ( 'Date'[Column] ) - 4
        ),
        [Beginning Inventories]
    )
)

Result is as below.

vrzhoumsft_0-1727925604990.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

I have got another solution that seems to be simpler.  The DAX formulas for Purchase and TTM Purchase have been modified like that

Purchase =
SUMX(
    SUMMARIZE(
        'Date',
        'Date'[Year],
        'Date'[Quarter]
    ),
    [Ending Inventories] - [Beginning Inventories] + [COGS]
)
and
TTM Purchase =
VAR     Purchase =
CALCULATE(
    [Purchase],
    DATESINPERIOD(
        'Date'[Date Key],
        Max('Date'[Date Key]),
        -4,
        QUARTER
    ),
    FILTER(
        All('Date'),
        Max('Date'[Date Key]) > Date(2015,9,30)
    )
)
Return
Purchase

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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