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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Javierco
Helper I
Helper I

Take latest data conditional on source

I have two sources of data (suppliers) that update product inventory data on different schedules. I would like know how much inventory is available (latest read).

 

Input data looks like this:

 

sourcedateqty
supplier 1   1/1/20214
supplier 1   1/9/20211
supplier 2   1/12/202110

 

Desired output would be a measure with the sum of the latest records for supplier 1 and supplier 2: 11 units (10+1)

This one works well with just one supplier: 

 

calculate(sumX(inventory_v2, inventory_v2[inventory_amount] ,LASTDATE(sellout_v2[sales_date]))

 

Any help would be much appreciated

 

1 ACCEPTED SOLUTION
v-cazheng-msft
Community Support
Community Support

Hi @Javierco 

 

You may try this Measure.

SumOfLatestRecords =

VAR LatestDate =

    ADDCOLUMNS (

        'Table',

        "latest", CALCULATE ( LASTDATE ( 'Table'[date] ), ALLEXCEPT ( 'Table', 'Table'[source] ) )

    )

RETURN

    CALCULATE (

        SUM ( 'Table'[qty] ),

        FILTER ( LatestDate, 'Table'[date] = [latest] )

    )

 

Then, the result will look like this.

vcazhengmsft_0-1644825720738.png

 

Also, attached the pbix file as reference.

 

Best Regards,

Community Support Team _ Caiyun

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let me know. Thanks a lot!

View solution in original post

4 REPLIES 4
v-cazheng-msft
Community Support
Community Support

Hi @Javierco 

 

You may try this Measure.

SumOfLatestRecords =

VAR LatestDate =

    ADDCOLUMNS (

        'Table',

        "latest", CALCULATE ( LASTDATE ( 'Table'[date] ), ALLEXCEPT ( 'Table', 'Table'[source] ) )

    )

RETURN

    CALCULATE (

        SUM ( 'Table'[qty] ),

        FILTER ( LatestDate, 'Table'[date] = [latest] )

    )

 

Then, the result will look like this.

vcazhengmsft_0-1644825720738.png

 

Also, attached the pbix file as reference.

 

Best Regards,

Community Support Team _ Caiyun

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let me know. Thanks a lot!

tamerj1
Super User
Super User

Hi @Javierco 
Here is a sample file that contains the solution https://www.dropbox.com/t/G4SVVdi5t5w5tlMS

 

Basically, you need to create a new calculated column that retrieves the last order date per supplier for each record:

Last Date = 
MAXX (
    FILTER (
        Data,
        Data[source] = EARLIER ( Data[source] )
    ),
    Data[date]
)

Untitled.png
Then you can create a simple measure that performs SUMX over a filtered table:

Last Date Qty = 
VAR LastDateTable = 
    FILTER ( 
        Data,
        Data[date] = Data[Last Date]
    )
VAR Result =
    SUMX (
        LastDateTable,
        Data[qty]
    )
RETURN
    Result 

 Untitled.png

Anonymous
Not applicable

Hi Javierco,

Please Try This measure And let me know your Answer.

My Measure =
VAR _latest =
       MAX ( 'Table'[Date] )
VAR _2nd_latest =
      MAXX ( FILTER ( 'Table', 'Table'[Date] < _latest ), 'Table'[Date] )
VAR _FilterTable =
       FILTER ( 'Table', 'Table'[Source] IN { "suppliar1", "suppliar2" } )
VAR _Result =
       CALCULATE (
              SUM ( 'Table'[qty] ),
              FILTER (
                  _FilterTable,
                  'Table'[Date] IN DATESBETWEEN ( 'Table'[Date], _2nd_latest, _latest )
              )
        )
RETURN
      _Result

ValtteriN
Super User
Super User

Hi,

Try something like this:

var _date = MAX('Calendar'[Date])
var _latestdate = CALCULATE(MAX('Table'[Date]),ALL('Table'[Date]),'Table'[Date]<=_date)
Return

CALCULATE(SUM('Table'[qty]),ALL('Table'[Date]),Table[Date]=_latestdate)

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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