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
BCheese
Regular Visitor

Help: Making a new table to that pulls the last entry for every month from original table

Hi everyone, just found this community so sorry if I am not doing this correctly. I am a new PBI user and working with this on a project. I have very very little experience in anything outside excel so trying to work with data in PBI is all new to me.
Anyway, I have the table shown below.

EoM table consolidation.PNG

I need to create a new table that consolidates the last entry for every month and for every product. I tried the method below but it did not work.

EoM table consolidation script.PNG

The Product ID is the cell model column if that helps. The error it is returning indicates that the line with YEAR (and MONTH) cannot reference a table column.

Any help is greatly appreciated.

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @BCheese 

 

You can try the following methods.
Sample data:

vzhangti_0-1678240174891.png

Table = 
FILTER ( 'OriginalTable',
    [Date] = CALCULATE ( MAX ( 'OriginalTable'[Date] ),
            FILTER ( 'OriginalTable',
                    [Product ID] = EARLIER ( OriginalTable[Product ID] )
                    && [Year] = EARLIER ( OriginalTable[Year] )
                    && [Month] = EARLIER ( OriginalTable[Month] )
            )
        )
)

vzhangti_1-1678240207818.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

9 REPLIES 9
Ashish_Mathur
Super User
Super User

Hi,

Share data in a format that can be pasted in an MS Excel file and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish, I have solved the original problem but no I have another. The new table (A) has been generated to give the last entry for each month for each product. Now I have tried to filter Table A and create Table B with the most recent entries for each product. So there should just be one entry for each product being the most recent, past value. But something is wrong. This is the code for Table B

BCheese_0-1678357961837.png

 

So this is mostly correct but it is missing other cell models. There should be 5 entries here. It is only looking at the most recent date, not the most recent date by cell model. I tried setting it up to filter by cell model first but that did not work. 

Table A data

Product IDYearMonthlastdatelastinventoryvalue
A202422/26/2024 0:00207809
A202333/27/2023 0:00989734
A202433/11/2024 0:00102619
A202344/24/2023 0:00941434
B202322/21/2023 0:00224000
B202433/28/2024 0:00448000
B202444/29/2024 0:00320235
C202322/27/2023 0:00149275
C202422/16/2024 0:0097975
C202333/27/2023 0:00358875
C202433/28/2024 0:0085975
C202344/28/2023 0:00402475
C202444/12/2024 0:0067975
D202322/21/2023 0:000
D202422/16/2024 0:00686990
D202433/28/2024 0:00534400
D202344/28/2023 0:00-2000
D202444/8/2024 0:00329980
E202322/21/2023 0:00221429
E202422/23/2024 0:00147019
E202433/28/2024 0:00146609
E202344/28/2023 0:00251429
E202444/26/2024 0:00133829
F202322/27/2023 0:00251401
F202422/16/2024 0:00259821
F202333/27/2023 0:00207751
F202433/28/2024 0:00190326
F202344/27/2023 0:00182251

I hope this makes sense. Any further help is greatly appreciated. 

BR, Will 

Hi,

Based on the table that you have shared, show the expected result.  Should it be a measure or a calculated column formula solution?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

The result for the sample data should be the table:

Product IDYearMonthlastdatelastinventoryvalue
B202322/21/2023 0:00224000
C202322/27/2023 0:00149275
D202322/21/2023 0:000
E202322/21/2023 0:00221429
F202322/27/2023 0:00251401

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-zhangti
Community Support
Community Support

Hi, @BCheese 

 

You can try the following methods.
Sample data:

vzhangti_0-1678240174891.png

Table = 
FILTER ( 'OriginalTable',
    [Date] = CALCULATE ( MAX ( 'OriginalTable'[Date] ),
            FILTER ( 'OriginalTable',
                    [Product ID] = EARLIER ( OriginalTable[Product ID] )
                    && [Year] = EARLIER ( OriginalTable[Year] )
                    && [Month] = EARLIER ( OriginalTable[Month] )
            )
        )
)

vzhangti_1-1678240207818.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

Hi again, ok so I have tried now for a bit to filter down to the most recent entries for each product. But something is wrong. 

BCheese_0-1678288500569.png

So this is mostly correct but it is missing other cell models. There should be 5 entries here. It is only looking at the most recent date, not the most recent date by cell model. I tried setting it up to filter by cell model first but that did not work. 

Hi! Thanks for the help. This is exactly the correct result that should be achieved! Thanks so much for the help. I just learned a lot about this. That was super easy to just filter a table. Cool. 

 

Now I have a follow up. I am trying to further filter this table. I need a new table that filters down to just the current inventory for each product, ie. the most recent, earlier date. I will try this now. 

BCheese
Regular Visitor

I have figured out a portion of this but I am still not getting the correct values. The formula I am using now is:

BCheese_0-1678111897192.png

However, it seems to want to return the value for "lastinverntoryvalue" corresponding to the last entry from the original table where the "demand" column is blank. It is not returning the value corresponding to the "lastdate" entry which is what I want. 

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.