The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
For simplicity I have the tables FACT Sales, DIM Customer and DIM Date. My report table is based on this and has columns for each customer and shows the sales sum for each year (2019-2022).
Definition new customer = Sales in selected year, but no sales in previous year; For example sales>0 in 2021, but no sales in 2020.
Definition lost customer = No sales in selected year, but sales in previous year; For example no sales in 2021, but sales>0 in 2020.
Now I want a slicer that contains the values N2019, N2020, N2021, N2022, L2019, L2020, L2021, L2022. N = new customer; L = lost customer. For example, when I select the value N2020 I want to see only those customer in the report table with sales>0 in 2020, but no sales in 2019.
Is this possible? If yes, how? If not, what would be other possibilities to reach my goal?
Solved! Go to Solution.
Hi @TimmK ,
You may try this solution.
1 Create a table containing the values N2019, N2020, N2021, N2022, L2019, L2020, L2021, L2022
2 Create a Measure
New Or Lost Customers =
VAR selectedVal =
SELECTEDVALUE ( SlicerTable[SelectedValue] )
VAR NL =
LEFT ( selectedVal, 1 )
VAR Year_ =
VALUE ( RIGHT ( selectedVal, 4 ) )
VAR Cur_Year =
CALCULATE (
SUM ( 'FACT Sales'[Amount] ),
FILTER ( 'FACT Sales', YEAR ( 'FACT Sales'[Date] ) = Year_ )
)
VAR Pre_Year =
CALCULATE (
SUM ( 'FACT Sales'[Amount] ),
FILTER ( 'FACT Sales', YEAR ( 'FACT Sales'[Date] ) = Year_ - 1 )
)
VAR IsCurBlank =
IF ( ISBLANK ( Cur_Year ), 0, 1 )
VAR IsPreBlank =
IF ( ISBLANK ( Pre_Year ), 0, 1 )
VAR CountForNew =
CALCULATE (
DISTINCTCOUNT ( 'FACT Sales'[Customer Key] ),
FILTER ( 'FACT Sales', IsCurBlank = 1 && IsPreBlank = 0 )
)
VAR CountForLost =
CALCULATE (
DISTINCTCOUNT ( 'FACT Sales'[Customer Key] ),
FILTER ( 'FACT Sales', IsCurBlank = 0 && IsPreBlank = 1 )
)
RETURN
IF ( NL = "N", CountForNew, CountForLost )
3 Use the Measure above as the visual filter of the Table visual
Then, the result will look like this.
Also, attached the pbix file as reference.
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 me know. Thanks a lot!
Best Regards,
Community Support Team _ Caiyun
Hello:
There are a handul of steps needed.
First build a slicer table.
I named it SelectedMeasure.
Then create New & Lost Measures for each of the eight categories. I'll paste a new and lost one for 2021 next:
Example:
Then put your final measure to coincide with your slicer selection:
Hi @TimmK ,
You may try this solution.
1 Create a table containing the values N2019, N2020, N2021, N2022, L2019, L2020, L2021, L2022
2 Create a Measure
New Or Lost Customers =
VAR selectedVal =
SELECTEDVALUE ( SlicerTable[SelectedValue] )
VAR NL =
LEFT ( selectedVal, 1 )
VAR Year_ =
VALUE ( RIGHT ( selectedVal, 4 ) )
VAR Cur_Year =
CALCULATE (
SUM ( 'FACT Sales'[Amount] ),
FILTER ( 'FACT Sales', YEAR ( 'FACT Sales'[Date] ) = Year_ )
)
VAR Pre_Year =
CALCULATE (
SUM ( 'FACT Sales'[Amount] ),
FILTER ( 'FACT Sales', YEAR ( 'FACT Sales'[Date] ) = Year_ - 1 )
)
VAR IsCurBlank =
IF ( ISBLANK ( Cur_Year ), 0, 1 )
VAR IsPreBlank =
IF ( ISBLANK ( Pre_Year ), 0, 1 )
VAR CountForNew =
CALCULATE (
DISTINCTCOUNT ( 'FACT Sales'[Customer Key] ),
FILTER ( 'FACT Sales', IsCurBlank = 1 && IsPreBlank = 0 )
)
VAR CountForLost =
CALCULATE (
DISTINCTCOUNT ( 'FACT Sales'[Customer Key] ),
FILTER ( 'FACT Sales', IsCurBlank = 0 && IsPreBlank = 1 )
)
RETURN
IF ( NL = "N", CountForNew, CountForLost )
3 Use the Measure above as the visual filter of the Table visual
Then, the result will look like this.
Also, attached the pbix file as reference.
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 me know. Thanks a lot!
Best Regards,
Community Support Team _ Caiyun
@TimmK , You have to create an independent table with values New Customer and Lost Customer and Retained Customer
Example measure to check sales
YTD = calculate([Sales],datesYtd('Date'[Date]))
LYTD = calculate([Sales],DATESYTD(DATEADD('Date'[Date],-1,MONTH)))
Type =
Switch( True(),
ISBLANK([YTD]) && not(ISBLANK([LYTD]) , "Lost Customer",
ISBLANK([LYTD]) && not(ISBLANK([YTD]) , "New Customer",
"Retained Customer"
)
Assume Table with three value as Bucket
New measure =
Countx(filter(VALUES(Customer[Customer Id]) , [Type] = max(Bucket[Type])), [Customer ID])
New measure sales
=
Countx(filter(VALUES(Customer[Customer Id]) , [Type] = max(Bucket[Type])), [sales])
Dynamic Segmentation Bucketing Binning
https://community.powerbi.com/t5/Quick-Measures-Gallery/Dynamic-Segmentation-Bucketing-Binning/m-p/1...
Dynamic Segmentation, Bucketing or Binning: https://youtu.be/CuczXPj0N-k
Thank you, but it seems this is not exactly the solution I am looking for. I want a slicer that contains the values N2019, N2020, N2021, N2022, L2019, L2020, L2021, L2022. For example, when I select N2020 my report table that lists all customers should be reduced to only those customers with sales in 2020, but no sales in 2019.
Hi @TimmK
What about the lost sales? Are you going to consider the previous sales as the lost value for the selected year?
@TimmK
Refer to sample file with the solution https://www.dropbox.com/t/URCvZUxrO8tQbALX
One way to do that is by creating a calculated column
New/Leaving/Continuing =
VAR CurrentCustomer =
Sales[Customer Key]
VAR CurrentYear =
YEAR ( Sales[Date] )
VAR PreviousYearSales =
COUNTROWS (
FILTER (
Sales,
Sales[Customer Key] = CurrentCustomer
&& YEAR ( Sales[Date] ) = CurrentYear - 1
)
)
VAR NextYearSales =
COUNTROWS (
FILTER (
Sales,
Sales[Customer Key] = CurrentCustomer
&& YEAR ( Sales[Date] ) = CurrentYear + 1
)
)
RETURN
IF (
PreviousYearSales = 0,
"N" & YEAR ( Sales[Date] ),
IF (
YEAR ( Sales[Date] ) + 1 <= YEAR ( NOW() ),
IF (
NextYearSales = 0,
"L" & YEAR ( Sales[Date] ) + 1,
"C" & YEAR ( Sales[Date] )
),
"C" & YEAR ( Sales[Date] )
)
)
The sales that are neither new nor lost are considered continuing sales. The report shall look like this
Please let me know if this answers your query or if you need any further modifications.
User | Count |
---|---|
12 | |
9 | |
6 | |
6 | |
6 |
User | Count |
---|---|
24 | |
14 | |
14 | |
9 | |
7 |