Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Group by first date

I am tryingto find the % of members who use the partner as their first partner based on date. Then I want to visuzalize this.

 

10% use X as their first

30% use XXX as their first.

 

PartnerNamePurchase DateMember Number
X2022-02-210040
XX2020-01-303395
XXX2021-02-120520
XXXX2020-09-280146
XX2019-10-054640
XX2020-11-050955
XXX2019-10-023786
XXXX2021-08-255406
X2019-10-024703
XX2020-09-284365
XXXX2021-01-215435
XX2020-03-205068
XXX2021-11-034907
XX2020-07-075355
XXX2021-10-224641
XXXX2020-06-050076
XXX2019-12-175694
XX2020-10-064939
XXX2021-08-180185
XXX2019-10-121005
XX2021-02-175223
XX2020-09-294658
XXX2020-10-013037
x2020-09-273735
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Anonymous ,

     

    According to your statement, I think there should be multiple parentnames in each member. You want to get the percentage of first parent by date for each member. I suggest you to create a virtual table with only firstdate and parentname in firstdate for each member.

    Measure:

    Measure = 
    VAR _MinDateParent_Table = 
    SUMMARIZE (
        'Table' ,
        'Table'[Member Number],
        "MinDate", CALCULATE ( MIN ( 'Table'[Purchase Date] ) ),
        "ParentName",
            CALCULATE (
                MAX ( 'Table'[PartnerName] ),
                FILTER ( 'Table', 'Table'[Purchase Date] = MIN ( 'Table'[Purchase Date] ) )
            )
    )
    VAR _Membercount = CALCULATE(DISTINCTCOUNT('Table'[Member Number]),ALL('Table'))
    VAR _COUNT_MemberbyParent = COUNTAX(_MinDateParent_Table,[Member Number])
    RETURN
    DIVIDE(_COUNT_MemberbyParent,_Membercount)

    Result is as below.

     

     

    Best Regards,
    Rico Zhou

     

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

     

4 Replies

  • Migasuke's avatar
    Migasuke
    Memorable Member

    Hi Anonymous ,
    Depends if you need to use dax or PQ.
    I would do the transformation probably in PQ since it's quite easy to do.

    Try to use this code:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bZFbCsQgDEX30u8GbhLjYycDQ/e/jUnUgVYL/sjl5HHy/R6f4zwEIgQhYf8ACcd1ejIjEJgU/lFtNqOZcWAsgZn8sRvYSGqEnPK9JjdiT80/KW/tmEeEZs92E4t2Wmpe2jlVSQK0hBmuWCrQdbk5Y9Jse0UeUiyprZyShBRDrquU2ECjZkNZseIvMLXNpU8pMpzw7jJPKyh5s+JH6EVzS6vMIPso2rbbVeJxnvomut+Vgefm4+S9m8ibzNY3sEXKmCRcKrTcrjOp0o8alq8f", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [PartnerName = _t, #"Purchase Date" = _t, #"Member Number" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"PartnerName", type text}, {"Purchase Date", type date}, {"Member Number", Int64.Type}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"PartnerName"}, {{"Member Number", each List.Sum([Member Number]), type nullable number}, {"MinDate", each List.Min([Purchase Date]), type nullable date}})
    in
        #"Grouped Rows"
  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Thanks for the quick reply, Would you be able to show me this in DAX as I am using Direct Query. 

     

    Kindly, 

     

    LKtheNoob.

    • Migasuke's avatar
      Migasuke
      Memorable Member

      Hi,

      Try to check my PBIX file.
      I have creaed custom column, which calculate the MIN date for every PartnerName, so you can easily identify the first date.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    According to your statement, I think there should be multiple parentnames in each member. You want to get the percentage of first parent by date for each member. I suggest you to create a virtual table with only firstdate and parentname in firstdate for each member.

    Measure:

    Measure = 
    VAR _MinDateParent_Table = 
    SUMMARIZE (
        'Table' ,
        'Table'[Member Number],
        "MinDate", CALCULATE ( MIN ( 'Table'[Purchase Date] ) ),
        "ParentName",
            CALCULATE (
                MAX ( 'Table'[PartnerName] ),
                FILTER ( 'Table', 'Table'[Purchase Date] = MIN ( 'Table'[Purchase Date] ) )
            )
    )
    VAR _Membercount = CALCULATE(DISTINCTCOUNT('Table'[Member Number]),ALL('Table'))
    VAR _COUNT_MemberbyParent = COUNTAX(_MinDateParent_Table,[Member Number])
    RETURN
    DIVIDE(_COUNT_MemberbyParent,_Membercount)

    Result is as below.

     

     

    Best Regards,
    Rico Zhou

     

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