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
Efftronics
New Member

I want who are the customers continuing with organization and who are not ? from last n years

I have a list of customer details like customer name, Order date, ordered products. I want who are the customers continuing with organization and who are not ? from last "n" years based on order date.

where "n" based on selection.

1 ACCEPTED SOLUTION
Samarth_18
Community Champion
Community Champion

Hi @Efftronics 

 

You can create a custom table with below code for putting it as slicer to filter data based on last n years:-

 

year_counts = 
var total_years = YEAR(MAX(customer_details[order_Date])) - YEAR(MIN(customer_details[order_Date]))
return GENERATESERIES(1,total_years,1)

 

This will give you number of years based on available data

Samarth_18_1-1627622321261.png

 

Now you create a measure with below code to filter your customer details:-

 

filter_last_n_year =
VAR selected_year =
    SELECTEDVALUE ( 'Table 3'[NumberOfYear] )
RETURN
    IF (
        YEAR ( MAX ( customer_details[order_date] ) ) <= YEAR ( TODAY () )
            && YEAR ( MAX ( customer_details[order_date] ) )
                >= ( YEAR ( TODAY () ) - selected_year ),
        1,
        0
    )

 

Use it as visual level like below:-

Samarth_18_2-1627622583196.png

 

It would be better if you could share some sample data with expected output. So that people can provide you more precised solution.

Thanks

Samarth

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

View solution in original post

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

Hi @Efftronics ,

 

I think the reference provided by @Samarth_18  is helpful.

 

If there are still problems, whether you can provide a test data model (delete sensitive information) and specific needs, I will answer you as soon as possible.


Best Regards,
Henry


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

Samarth_18
Community Champion
Community Champion

Hi @Efftronics 

 

You can create a custom table with below code for putting it as slicer to filter data based on last n years:-

 

year_counts = 
var total_years = YEAR(MAX(customer_details[order_Date])) - YEAR(MIN(customer_details[order_Date]))
return GENERATESERIES(1,total_years,1)

 

This will give you number of years based on available data

Samarth_18_1-1627622321261.png

 

Now you create a measure with below code to filter your customer details:-

 

filter_last_n_year =
VAR selected_year =
    SELECTEDVALUE ( 'Table 3'[NumberOfYear] )
RETURN
    IF (
        YEAR ( MAX ( customer_details[order_date] ) ) <= YEAR ( TODAY () )
            && YEAR ( MAX ( customer_details[order_date] ) )
                >= ( YEAR ( TODAY () ) - selected_year ),
        1,
        0
    )

 

Use it as visual level like below:-

Samarth_18_2-1627622583196.png

 

It would be better if you could share some sample data with expected output. So that people can provide you more precised solution.

Thanks

Samarth

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect 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.