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.
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.
Solved! Go to Solution.
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
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:-
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
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.
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
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:-
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
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
98 | |
77 | |
66 | |
54 |
User | Count |
---|---|
144 | |
104 | |
102 | |
88 | |
63 |