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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
bourne2000
Helper V
Helper V

How to show the last five transactions dynamically ?

Hi

 

I have a retail data which has mostly commodity product.  Example of data as follow,

 

Invoice numberInvoice DateProductInvoice Amount
20A101.10.2021Jam500
20A202.10.2021Bread100
21B201.10.2021Bread120
22C303.10.2021Bread14
24C504.10.2021Bread24
24C605.10.2021Jam29
24C706.10.2021Jam500
27a307.10.2021Jam500
28d208.10.2021Jam93
29f309.10.2021Jam192
29r310.10.2021Jam10
24hc11.10.2021Bread2
25hc05.10.2021Bread102
278A04.10.2021Bread102
293E11.10.2021Bread10
324R12.10.2021Choclate3
33C309.10.2021Choclate3
35R305.10.2021Choclate5

 

I want to show the product pricing trend for the last 5 invoices. All the invoice number is unique. For example, I need to create a simple bar graph for product vs Invoice amount for the last five invoices only. Some of the product like choclate has only one invoices, in that case it can show the one invoice. I have a product filter and date filter. I need to see the product pricing trend for last five invoices for any product dynamically. 

 

Can anyone advise me how to do that?

 

Attach sample pbix file https://we.tl/t-DY7ZAZkzfW

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I do not know how your desired outcome looks like, but please check the below picture and the sample pbix file's link down below.

 

Picture1.png

 

Invoice amount last 5 per product : =
VAR _lastN = 5
VAR _currentproduct =
MAX ( 'Table'[Product] )
VAR _topNtable =
TOPN (
_lastN,
FILTER ( ALL ( 'Table' ), 'Table'[Product] = _currentproduct ),
CALCULATE ( MAX ( 'Table'[Invoice Date] ) ), DESC
)
RETURN
CALCULATE ( [Invoice amount measure :], KEEPFILTERS ( _topNtable ) )

 

 

 

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.


Go to My LinkedIn Page


View solution in original post

2 REPLIES 2
v-henryk-mstf
Community Support
Community Support

Hi @bourne2000 ,

 

According to your description, you want to filter the Invoice Amount by dynamic dates, corresponding to the latest 5 dates under each Product. you need to create a separate date table. I have done the test with the following reference

M = 
VAR sel_data =
    SELECTEDVALUE ( 'Table 2'[Date] )
RETURN
    CALCULATE (
        SUM ( 'Table'[Invoice Amount] ),
        KEEPFILTERS (
            TOPN (
                5,
                FILTER (
                    ALLSELECTED ( 'Table' ),
                    MAX ( 'Table'[Product] ) = 'Table'[Product]
                        && 'Table'[Invoice Date] < sel_data
                ),
                'Table'[Invoice Date], DESC
            )
        )
    )

vhenrykmstf_0-1633938105227.png

 


If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.


Best Regards,
Henry


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

Jihwan_Kim
Super User
Super User

Hi,

I do not know how your desired outcome looks like, but please check the below picture and the sample pbix file's link down below.

 

Picture1.png

 

Invoice amount last 5 per product : =
VAR _lastN = 5
VAR _currentproduct =
MAX ( 'Table'[Product] )
VAR _topNtable =
TOPN (
_lastN,
FILTER ( ALL ( 'Table' ), 'Table'[Product] = _currentproduct ),
CALCULATE ( MAX ( 'Table'[Invoice Date] ) ), DESC
)
RETURN
CALCULATE ( [Invoice amount measure :], KEEPFILTERS ( _topNtable ) )

 

 

 

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.


Go to My LinkedIn Page


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.