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
AsadChanna14
Helper I
Helper I

Need a help with customer count who switch product.

Hello,

 

I am a new user learner of Dax.  Can you advise me on the following query?

 

For the following table, I need to find the total number of customers who switched from Financial to Non-Financial products and Non-Financial to Financial. If the customer bought both products on the same day then It is called a same-day purchase.  I want the results in one column.

 

I would really appreciate any given help. 

Many Thanks,

chana

 

Customer No.Date ProductResult
11/1/2000Financial Financial to Non-Financial
12/1/2000Non-Financial Financial to Non-Financial
23/1/2000Non-FinancialNon-Financial to Financial
24/1/2000FinancialNon-Financial to Financial
31/2/2000FinancialSame-Day
31/2/2000Non-FinancialSame-Day
41/2/2000Non-FinancialSame-Day
41/2/2000FinancialSame-Day
51/5/2000FinancialFinancial to Non Non-Financial
52/5/2000Non-FinancialFinancial to Non Non-Financial
53/5/2000FinancialFinancial to Non Non-Financial
54/5/2000Non-FinancialFinancial to Non Non-Financial
1 ACCEPTED SOLUTION
Anonymous
Not applicable

[# Switch (F->NF)] =
// swap these to get the NF->F version
var FromState = "financial"
var ToState = "non-financial"
return
SUMX(
	DISTINCT( T[Customer No.] ),
	CALCULATE(
		var First2Rows =
			topn(2,
				T,
				T[Date],
				ASC
			)
		var First2RowsRanked =
			ADDCOLUMNS(
				First2Rows,
				"@Rank",
					RANKX(
						First2Rows,
						T[Date],, // 2 commas
						ASC,
						DENSE
					)
			)
		var IsFromFtoNF =
			not ISEMPTY(
				filter(
					First2RowsRanked,
					[@Rank] = 1
					&&
					T[Product] = FromState
				)
			)
			&&
			not ISEMPTY(
				filter(
					First2RowsRanked,
					[@Rank] = 2
					&&
					T[Product] = ToState
				)
			)
		return
			DIVIDE( IsFromFtoNF, IsFromFtoNF )
	)
)

Something like this... I guess. Be aware, though, that the measure is totally aware of all the filters in the current context.

View solution in original post

3 REPLIES 3
AsadChanna14
Helper I
Helper I

@Anonymous :

 

Thank you for the reply. It is not working on my end. Just to be clear Customer No is the Customer ID Number. 

 

 

Anonymous
Not applicable

Telling me "not working on my end" is no information at all. What's not working? Why is it not working? What do you get? Where's the problem? With respect to field names... well, I guess you're good enough to adjust my code to work with your model, right?

Anonymous
Not applicable

[# Switch (F->NF)] =
// swap these to get the NF->F version
var FromState = "financial"
var ToState = "non-financial"
return
SUMX(
	DISTINCT( T[Customer No.] ),
	CALCULATE(
		var First2Rows =
			topn(2,
				T,
				T[Date],
				ASC
			)
		var First2RowsRanked =
			ADDCOLUMNS(
				First2Rows,
				"@Rank",
					RANKX(
						First2Rows,
						T[Date],, // 2 commas
						ASC,
						DENSE
					)
			)
		var IsFromFtoNF =
			not ISEMPTY(
				filter(
					First2RowsRanked,
					[@Rank] = 1
					&&
					T[Product] = FromState
				)
			)
			&&
			not ISEMPTY(
				filter(
					First2RowsRanked,
					[@Rank] = 2
					&&
					T[Product] = ToState
				)
			)
		return
			DIVIDE( IsFromFtoNF, IsFromFtoNF )
	)
)

Something like this... I guess. Be aware, though, that the measure is totally aware of all the filters in the current context.

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