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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
rile14
Helper I
Helper I

How can I get the latest value for each company based on a reporting date?

Hi All,

 

I'm trying to write a DAX that will return the latest value for each company, based on a specific reporting date.

Each company has multiple transactions with different transaction dates. Some of them have a transaction date that is equal to the reporting date, but some of them have the latest transaction date earlier. I want to get all the latest values and the correct total in the table. I can return all the latest values, but the total is not correct.

 

Here is the dataset:

rile14_0-1674207329202.png

Reporting date is 31/12/2021, and the expected result is 6.500.951.

 

Can anyone assist me with this,  please?

Thanks.

 

 

1 ACCEPTED SOLUTION
rile14
Helper I
Helper I

I've figured it out. 

First I have created this measure:

 

Transaction Value =
VAR maxasAtDate =
    MAX ( 'As At Date'[Date] )
VAR maxrepDt =
    MAX ( 'Date'[Date] )
VAR maxdt =
    MIN ( maxasAtDate, maxrepDt )
VAR maxTrxDate =
    CALCULATE ( MAX ( 'Test File'[Transaction Date] ), 'Date'[Date] <= maxdt )
RETURN
    CALCULATE (
        SUM ( 'Test File'[Value] ),
        ALL ( 'Date' ),
        'Date'[Date] >= maxTrxDate,
        'Date'[Date] <= maxdt
    )

 

And then another one to get the total amount correctly displayed in a table:

 

 Transaction Value (Total) =
SUMX ( SUMMARIZE ( 'Test File', Dim_Company[Company] ), [Transaction Value] )

 

 

 

View solution in original post

3 REPLIES 3
rile14
Helper I
Helper I

I've figured it out. 

First I have created this measure:

 

Transaction Value =
VAR maxasAtDate =
    MAX ( 'As At Date'[Date] )
VAR maxrepDt =
    MAX ( 'Date'[Date] )
VAR maxdt =
    MIN ( maxasAtDate, maxrepDt )
VAR maxTrxDate =
    CALCULATE ( MAX ( 'Test File'[Transaction Date] ), 'Date'[Date] <= maxdt )
RETURN
    CALCULATE (
        SUM ( 'Test File'[Value] ),
        ALL ( 'Date' ),
        'Date'[Date] >= maxTrxDate,
        'Date'[Date] <= maxdt
    )

 

And then another one to get the total amount correctly displayed in a table:

 

 Transaction Value (Total) =
SUMX ( SUMMARIZE ( 'Test File', Dim_Company[Company] ), [Transaction Value] )

 

 

 

rile14
Helper I
Helper I

Mahesh0016
Super User
Super User

@rile14 Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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