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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Dax help with conversion

Hi community, 

 

Can you please help me writing following in measure and Column. 

 

I have product  two products in data ( F and NF) . I  want create measure and column where I could identify customer has converted from NF to F.  I have two years of data and cut of time to look NF product  is 365 days. that means if customer has acquired  F  product  then code check  product NF in last one years  of product F acquired  date.   

 

ID | Product Name  |  Date                     |    Product F Aquired |   NF -> F

 

1       NF                     2020/Sept/ 2               N

1       F                        2021/Jan/1                  Y                                   Y

2      NF                      2020/Feb/2020            N

2      F                         2021/Dec /2021          Y                                   N

3      NF                      20/ March/2021          N                                       

3       F                      20/July/2021               Y                                     Y

 

Thanks,

Chans. 

 

1 ACCEPTED SOLUTION
v-cazheng-msft
Community Support
Community Support

Hi @Anonymous 

 

Please try this Measure or Calculated column.

1 Measure

IsNF -> F =

VAR PreDate =

    CALCULATE (

        MAX ( 'Table'[Date] ),

        FILTER (

            ALL ( 'Table' ),

            'Table'[ID] = MAX ( 'Table'[ID] )

                && 'Table'[Date] < MAX ( 'Table'[Date] )

                && [Product F Acquired] = "N"

        )

    )

RETURN

    IF (

        ISBLANK(PreDate),

        "",

        IF ( DATEDIFF ( PreDate, MAX ( 'Table'[Date] ), DAY ) < 365, "Y", "N" )

    )

 

 

2 Calculated column

IsNF -> F_Col =

VAR PreDate =

    CALCULATE (

        MAX ( 'Table'[Date] ),

        FILTER (

            ALL ( 'Table' ),

            'Table'[ID] = EARLIER ( 'Table'[ID] )

                && 'Table'[Date] < EARLIER ( 'Table'[Date] )

                && [Product F Acquired] = "N"

        )

    )

RETURN

    IF (

        ISBLANK ( PreDate ),

        "",

        IF ( DATEDIFF ( PreDate, 'Table'[Date], DAY ) < 365, "Y", "N" )

    )

 

Then, the result should look like this.

vcazhengmsft_0-1642754976862.png

 

Attached the pbix file as reference.

 

Best Regards,

Community Support Team _ Caiyun

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

 

View solution in original post

2 REPLIES 2
v-cazheng-msft
Community Support
Community Support

Hi @Anonymous 

 

Please try this Measure or Calculated column.

1 Measure

IsNF -> F =

VAR PreDate =

    CALCULATE (

        MAX ( 'Table'[Date] ),

        FILTER (

            ALL ( 'Table' ),

            'Table'[ID] = MAX ( 'Table'[ID] )

                && 'Table'[Date] < MAX ( 'Table'[Date] )

                && [Product F Acquired] = "N"

        )

    )

RETURN

    IF (

        ISBLANK(PreDate),

        "",

        IF ( DATEDIFF ( PreDate, MAX ( 'Table'[Date] ), DAY ) < 365, "Y", "N" )

    )

 

 

2 Calculated column

IsNF -> F_Col =

VAR PreDate =

    CALCULATE (

        MAX ( 'Table'[Date] ),

        FILTER (

            ALL ( 'Table' ),

            'Table'[ID] = EARLIER ( 'Table'[ID] )

                && 'Table'[Date] < EARLIER ( 'Table'[Date] )

                && [Product F Acquired] = "N"

        )

    )

RETURN

    IF (

        ISBLANK ( PreDate ),

        "",

        IF ( DATEDIFF ( PreDate, 'Table'[Date], DAY ) < 365, "Y", "N" )

    )

 

Then, the result should look like this.

vcazhengmsft_0-1642754976862.png

 

Attached the pbix file as reference.

 

Best Regards,

Community Support Team _ Caiyun

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

 

amitchandak
Super User
Super User

@Anonymous , A new column like

 


new column =
var _date1 = [Date]
var _date2 = date(year(_date1), month(_date1)-12, day(_date1))
var _cnt =countx(filter(Table, [Date]>= _date2 && [Date] <= _date1 && [Id] = earlier([ID]) && [Product Name] = "F"), [Product Name])
return
if( [Product Name] = "NF" && not(isblank(_cnt)) , "Y" , blank())

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.