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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
OpenMike13
Frequent Visitor

Finding first and last product purchased

Hello i have a table that has a membership rate purchased by a contact and has a monthly date if the contact has a membership for the countdate.

 

 

ContactIDCountdateRatename
11/15/2022Ind. Membership
12/15/2022Ind Membership
13/15/2022Deluxe Membership
21/15/2022Ind. Membership
22/15/2022Ind. Membership
23/15/2022Gold Membership

 

 

Im looking to find the first and last product purchased for each contact. So the output should look like 

 

ContactIDFirst ProductSecond Product
1Ind. MembershipDeluxe Membership
2Ind. MembershipGold Membership

 

Any help would be appreaciated! 

1 ACCEPTED SOLUTION
v-henryk-mstf
Community Support
Community Support

Hi @OpenMike13 ,

 

Try formula like below:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTLUNzTVNzIwMgKyPfNS9BR8U3OTUouKMzILlGJ1IGqM0NRgUWKMpMQlNae0IhXdICMslmFRQsAuIzS73PNzUlBsigUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ContactID = _t, Countdate = _t, Ratename = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ContactID", Int64.Type}, {"Countdate", type date}, {"Ratename", type text}}),
    #"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Meb", each if Text.Contains([Ratename], "Ind") then [Ratename] else null),
    #"Filled Down" = Table.FillDown(#"Added Conditional Column",{"Meb"}),
    #"Filtered Rows" = Table.SelectRows(#"Filled Down", each not Text.Contains([Ratename], "Ind"))
in
    #"Filtered Rows"
M =
VAR count_f =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER ( ALL ( 'Table' ), 'Table'[Ratename] = MAX ( 'Table'[Ratename] ) )
    )
VAR count_ =
    CALCULATE ( COUNTROWS ( 'Table' ), ALL ( 'Table' ) )
RETURN
    DIVIDE ( count_f, count_, BLANK () )

 

vhenrykmstf_0-1659684692560.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.

View solution in original post

5 REPLIES 5
v-henryk-mstf
Community Support
Community Support

Hi @OpenMike13 ,

 

Try formula like below:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTLUNzTVNzIwMgKyPfNS9BR8U3OTUouKMzILlGJ1IGqM0NRgUWKMpMQlNae0IhXdICMslmFRQsAuIzS73PNzUlBsigUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ContactID = _t, Countdate = _t, Ratename = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ContactID", Int64.Type}, {"Countdate", type date}, {"Ratename", type text}}),
    #"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Meb", each if Text.Contains([Ratename], "Ind") then [Ratename] else null),
    #"Filled Down" = Table.FillDown(#"Added Conditional Column",{"Meb"}),
    #"Filtered Rows" = Table.SelectRows(#"Filled Down", each not Text.Contains([Ratename], "Ind"))
in
    #"Filtered Rows"
M =
VAR count_f =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER ( ALL ( 'Table' ), 'Table'[Ratename] = MAX ( 'Table'[Ratename] ) )
    )
VAR count_ =
    CALCULATE ( COUNTROWS ( 'Table' ), ALL ( 'Table' ) )
RETURN
    DIVIDE ( count_f, count_, BLANK () )

 

vhenrykmstf_0-1659684692560.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.

tamerj1
Super User
Super User

Hi @OpenMike13 
Here is a sample file with the solution https://www.dropbox.com/t/N6FdYCFWIB4KEhh2

1.png2.png

First Product = 
MAXX (
    TOPN ( 1, Sheet1, Sheet1[Countdate], ASC ),
    Sheet1[Ratename]
)
Last Product = 
MAXX (
    TOPN ( 1, Sheet1, Sheet1[Countdate] ),
    Sheet1[Ratename]
)

 

These measures did as asked, thank you. question would there be a way to find the count/percentages of the combinations? For example the output would look like the table below

 

 Deluxe MembershipGold Membership
Ind. Membership50%50%

Hi @OpenMike13 
Sorry can you explain further this combinations thing?

Looking for an analysis of percetange of people upgrading/downgrading membership based on those rates. Hope that helps 

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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