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
Anonymous
Not applicable

Need help with writing DAX

Hello Community,

Can you please help me writing this query in Power BI DAX (Column).

I have table, where I want to find the customer converstions  from first product  to their last product. i.e converstion from Product A to B and B to A.   Also, There is no customers in data that have purchased two products on same day. Just to avoid ambguity, I will exclude the customers that purchased on same day. 
Note -  I want to exclude the products that are purchased on First day of year. 

 

I would really appreciate if you could help me with it. 

Many Thanks, Chana

Channa_0-1629899610283.png

 

 

 

 

 

1 ACCEPTED SOLUTION

Try this code for a calculated column:

 

 

 

Product Conversion =
VAR _Table =
    CALCULATETABLE (
        'Table',
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[ID] ),
            YEAR ( 'Table'[Date] ) = YEAR ( EARLIER ( 'Table'[Date] ) )
        )
    )
VAR DistVal =
    CALCULATE (
        COUNT ( 'Table'[Product] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[ID] ),
            YEAR ( 'Table'[Date] ) = YEAR ( EARLIER ( 'Table'[Date] ) )
        )
    )
RETURN
    IF (
        DistVal = 1,
        'Table'[Product] & "2" & 'Table'[Product],
        CONCATENATEX ( _Table, 'Table'[Product], "2", 'Table'[Date] )
    )

 

 

 

 

result.JPG

 

I've added a new row for ID 1 in 2021 so you can see the progression in case you have more than 2 operations in a year

 

As an alternative you could just list the progression based on the number of Products by year using:

 

Product Conversion =
VAR _Table =
    CALCULATETABLE (
        'Table',
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[ID] ),
            YEAR ( 'Table'[Date] ) = YEAR ( EARLIER ( 'Table'[Date] ) )
        )
    )

RETURN
    CONCATENATEX ( _Table, 'Table'[Product], "2", 'Table'[Date] )

 

 

To get:

res1.JPG

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

9 REPLIES 9
PaulDBrown
Community Champion
Community Champion

please post sample data (not an image) and a depiction of the expected outcome. Thanks!





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

Hi @PaulDBrown,  Please see below: I need result in column like Product Conversion TEST. 
Note: I want excludes data on First day of  year. 
Thank you in advance,

Asad

DateIDProductTEST COLProduct Conversion TEST
1/1/2020 0:006AA OnlyA2A
1/1/2020 0:007BB OnlyB2B
2/12/2020 0:001AA OnlyA2A
2/13/2020 0:006AA OnlyA2A
3/12/2020 0:001AA OnlyA2A
5/13/2020 0:005BB OnlyB2B
12/5/2020 0:005BB OnlyB2B
1/1/2021 0:001AA & BA2B
1/1/2021 0:003AA OnlyA2A
1/2/2021 0:002AA OnlyA2A
1/3/2021 0:002AA OnlyA2A
1/8/2021 0:001BA & BA2B
4/14/2021 0:004BB OnlyB2B

thanks for that. Do you want a measure or a calculated column?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

Calculate column please. Thanks!

 

Sure! Can you please explain the logic behind your Test Col? 
and please clarify the criteria. For example for ID = 1, you have AAAB but you your progression states:

AA

AA

AA

AB

Does that mean the criteria is current date vs. previous?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

Hi @PaulDBrown ,

 

Test col  reperesents if customers has only Product A or B or both  based on calendar year. 
 To know the conversion from Product A to B or B to A , I am looking to First and Last date of product purchases. 
Thank you, 

Chana

So is the calculation by year or progressive irrespective of the year?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

Calculation by Year. Thank you

Try this code for a calculated column:

 

 

 

Product Conversion =
VAR _Table =
    CALCULATETABLE (
        'Table',
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[ID] ),
            YEAR ( 'Table'[Date] ) = YEAR ( EARLIER ( 'Table'[Date] ) )
        )
    )
VAR DistVal =
    CALCULATE (
        COUNT ( 'Table'[Product] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[ID] ),
            YEAR ( 'Table'[Date] ) = YEAR ( EARLIER ( 'Table'[Date] ) )
        )
    )
RETURN
    IF (
        DistVal = 1,
        'Table'[Product] & "2" & 'Table'[Product],
        CONCATENATEX ( _Table, 'Table'[Product], "2", 'Table'[Date] )
    )

 

 

 

 

result.JPG

 

I've added a new row for ID 1 in 2021 so you can see the progression in case you have more than 2 operations in a year

 

As an alternative you could just list the progression based on the number of Products by year using:

 

Product Conversion =
VAR _Table =
    CALCULATETABLE (
        'Table',
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[ID] ),
            YEAR ( 'Table'[Date] ) = YEAR ( EARLIER ( 'Table'[Date] ) )
        )
    )

RETURN
    CONCATENATEX ( _Table, 'Table'[Product], "2", 'Table'[Date] )

 

 

To get:

res1.JPG

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






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.

Top Solution Authors