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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Filter in a DAX VAR (temp)

Hi!!

 

I Have a problem trying of filter a temp table in a measure:

 

i have a database with this structure:

 

useractiondateValue
1001register01/01/2020 
1001perfilation01/01/2020 
1001inversion02/01/20201000
1002register20/01/2020 
1002perfilation25/01/2020 
1003inversion12/01/20201200
1003inversion28/03/20201500

 

I need to create a measure for the number of users who made their first investment in a period, who also registered in that period. so, the first part of the function I already have, but I need to filter that they have been registered in the same period

 

New Inversions =
         VAR USERS = VALUES( Logs[Email] )
         VAR TABLE1 = CALCULATETABLE( VALUES( Logs[Email] ),
                                    ALL( Calendario[Date] ),
                                    DATESBETWEEN(Calendario[Date],[first_date],[User_start_date]))
RETURN
         COUNTROWS(
         EXCEPT( USERS,TABLE1 ) )

 

Additionally

first_date = first date of the database

User_start_date= start date in dashboard analysis range

 

1 ACCEPTED SOLUTION

This measure will count the number of users that registered and purchased in the same month. I don't know what "inversion" and "perfilation" mean, so I used the term "inversion" and made sure there was one in a month that someone registered, because your original data didn't have that.

 

So this table:

2020-04-20 18_23_51-DaxStudio - 2.10.2.png

will count 1 record where Inversion happened in the same month as the registration for a given user.

 

Registration Count = 
VAR UserPurchasePeriods =
	SELECTCOLUMNS(
		FILTER(
			Registrations,
			Registrations[action] = "inversion"
			),
			"User", Registrations[user],
			"Period", RELATED('Date'[YearMonth])
			)
VAR PurchaseInRegistrationPeriod =
	FILTER(
		Registrations,
		Registrations[action] = "register"
			&& RELATED('Date'[YearMonth]) in SELECTCOLUMNS( UserPurchasePeriods, "Period", [Period])
			&& Registrations[user] in SELECTCOLUMNS( UserPurchasePeriods, "User", [User])
			)
VAR RegistrationDate = 
	COUNTX(
		PurchaseInRegistrationPeriod,
		[Date]
		)
RETURN
RegistrationDate

 

See the PBIX linked here. . This needed a date table to work.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@Anonymous ,

For any period you need something like this


sumx(Summarize(Table,Table[user],Table[period],"_1"
countrows(filter(Table,Table[action] in{"register","inversion"}))),if([_1]>=2,1,0))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
edhans
Super User
Super User

Define "period." Same month, year, quarter?



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
Anonymous
Not applicable

The periods are months, excuse me, i forgot mention it 

This measure will count the number of users that registered and purchased in the same month. I don't know what "inversion" and "perfilation" mean, so I used the term "inversion" and made sure there was one in a month that someone registered, because your original data didn't have that.

 

So this table:

2020-04-20 18_23_51-DaxStudio - 2.10.2.png

will count 1 record where Inversion happened in the same month as the registration for a given user.

 

Registration Count = 
VAR UserPurchasePeriods =
	SELECTCOLUMNS(
		FILTER(
			Registrations,
			Registrations[action] = "inversion"
			),
			"User", Registrations[user],
			"Period", RELATED('Date'[YearMonth])
			)
VAR PurchaseInRegistrationPeriod =
	FILTER(
		Registrations,
		Registrations[action] = "register"
			&& RELATED('Date'[YearMonth]) in SELECTCOLUMNS( UserPurchasePeriods, "Period", [Period])
			&& Registrations[user] in SELECTCOLUMNS( UserPurchasePeriods, "User", [User])
			)
VAR RegistrationDate = 
	COUNTX(
		PurchaseInRegistrationPeriod,
		[Date]
		)
RETURN
RegistrationDate

 

See the PBIX linked here. . This needed a date table to work.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.