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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
beeisabelm
Microsoft Employee
Microsoft Employee

Sub-grouping table and conditional column populated from one column of a specific row

I have a table of user event names and adhoc info; Some of the events have adhoc info that needs to be used to set a conditional column values for all other rows that have same user ID. How do I create a DAX function to dynamically set the column value? 

 

 

EventNameUserIdAdhoc1Adhoc2UserTypeStatus
PageLoaded1 Product1  
SubmitButtonClicked1NewUser   
TransactionCompleted1    
PageLoaded2 Product1  
PageLoaded3 Product2  
SubmitButtonClicked3ExistingUser   

 

The desired result

 

 

EventNameUserIdAdhoc1Adhoc2UserTypeStatus
PageLoaded1 Product1NewUserSuccess
SubmitButtonClicked1NewUser NewUserSuccess
TransactionCompleted1  NewUserSuccess
PageLoaded2 Product1NewUserBailed
PageLoaded3 Product2ExistingUserSuccess
SubmitButtonClicked3ExistingUser ExistingUserBailed

 

Conditional column "UserType" - 

Table.AddColumn(#"Sources", "UserType", each if Text.StartsWith([EventName], "SubmitButtonClicked") then [Adhoc2] else if (Filter(Table, AllExcept[UserId], ??)) else null)

Conditional column "Status" - 

Table.AddColumn(#"Sources", "Status", each if [UserId] == LATER??[UserId] then "Success" else "Bailed")

 

Thank you for help!

3 REPLIES 3
v-yuta-msft
Community Support
Community Support

@beeisabelm ,

 

Could you please clarify more details/logic about dax statement below in your custom function?

Filter(Table, AllExcept[UserId], ??)

Community Support Team _ Jimmy Tao

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

UserType and Status are conditional columns. The table is pre-sorted by UserId and TimeStamp so the events happened in the correct order. (I ommitted the timestamp column in this sample table)
 
UserType is determined by Adhoc1 value when EventName is SubmitButtonClicked. I want to populate all other rows under same UserId with same UserType value. Ex. UserId 1 will have all rows with UserType "NewUser". UserId 3 will have all rows with UserType "ExistingUser". Otherwise, null.
 
Status is Success if the event is not the last event taken by the user. Status is Bailed if it is the last event by this user. Ex. UserId 1 PageLoaded event Status is Success. UserId 2 PageLoaded event Status is Bailed.
 
I am trying to iterate through the rows with same UserId to populate the conditional column, but not sure how to utilize the keyword "Ealier". Thank you for the help. @v-yuta-msft 

I was able to solve the first question with below DAX and create a new column

 

UserTypeGenerated = IF(CALCULATE(COUNTROWS(TableName),ALLEXCEPT('TableName',TableName[UserId]),TableName[UserType]="ExistingUser")>0,"ExistingUser","NewUser")

 

However, I still need help with the second one. @v-yuta-msft  Can you help?

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.