Dynamic Greeting Message based on Time and Login Users using DAX in Power BI.

DAX (Data Analysis Expressions) is a formula language used for data modeling and analysis in Microsoft Power BI. Using DAX users can create powerful data models and complex calculations.

DAX formulas can also contain variables, which are used to store intermediate results. Variables are defined using the VAR keyword, followed by the variable name and its value.

In this Tutorial we will discuss how to write the DAX for dynamic greeting based on time and login users.

Step 1:  Get the data (Name and Email) of users. You can access data from any sources. Like excel and any other databases.

load data in power BI desktop

Step 2: write the measure to find the name of currently logged-in user based on their email address

Login_User = CALCULATE( SELECTEDVALUE('User Table'[Name]),
FILTER('User Table', 'User Table'[Email]= USERPRINCIPALNAME())) 

In above DAX   CALCULATE and FILTER functions used to retrieve the username of the currently logged-in user based on their email address.

The SELECTEDVALUE function is used to return the value of the selected column from a single-row table, which in this case is the ‘Name’ column from the ‘User Table’.

The FILTER function is used to filter the rows of the ‘User Table’ based on the current user’s email address, which is obtained using the USERPRINCIPALNAME function.

Step 3: Write the measure for greeting based on time and current login user.

GREETING = VAR user = [Login_User]()

VAR hour = HOUR(NOW())
VAR minute = MINUTE(NOW())
VAR prefix = SWITCH(
                    TRUE(),
                    hour<12,"Good Morning ",
                    hour>=12 && hour<17,"Good Afternoon ",
                    "Good Evening "
             )
RETURN CONCATENATE( prefix, user) 

In above DAX, VAR (variable) and RETURN statements used to generate a greeting message based on the time of the day and the user’s name.

The user variable store the currently login user. And other two variables, ‘hour’ and ‘minute’ store the current hour and minute of the day using the NOW function.

The prefix variable is defined using the SWITCH function, which returns a different value based on the specified conditions. In this case, the condition checks if the hour is less than 12, between 12 and 17, or greater than 17, and returns a different greeting message accordingly.

Finally, the CONCATENATE function is used to concatenate the prefix and the ‘user’ variable to generate the final greeting message.

power bi
Please follow and like us:
error
fb-share-icon

2 thoughts on “Dynamic Greeting Message based on Time and Login Users using DAX in Power BI.”

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top