Code Generator | DAX

Dynamic Dashboard Greeting in DAX

This DAX measure generates a personalized greeting by combining the user's name with today's date and the last updated date of the dashboard data, enhancing the user experience in Power BI reports.


Empty image or helper icon

Prompt

Merge the following dax into one:

DashboardOverview = 
"Welcome to the BNI Insurance Dashboard! Today is " & FORMAT(TODAY(), "MMMM dd, yyyy") & 
". The data in this report is current as of " & FORMAT(TODAY() - 1, "MMMM dd, yyyy") & "."


make it like this one:

Greeting = 
VAR currentUser = USERPRINCIPALNAME()
VAR hour = HOUR(NOW())
VAR greetingText = SWITCH(
    TRUE(),
    hour < 12, "Good morning, ",
    hour < 18, "Good afternoon, ",
    "Good evening, "
)
RETURN greetingText & LEFT(currentUser, FIND("@", currentUser) - 1)

Answer

Merging DAX Expressions

The following DAX expression combines the functionalities of the DashboardOverview and Greeting measures into a single cohesive measure that dynamically generates a greeting message along with dashboard data.

Merged Functionality Overview

Purpose

This DAX function provides a welcome message, along with today's date and the last updated date for the dashboard data, tailored based on the time of the day and the username of the individual accessing the dashboard.

Code Implementation

DashboardGreeting = 
VAR currentUser = USERPRINCIPALNAME()
VAR hour = HOUR(NOW())
VAR greetingText = SWITCH(
    TRUE(),
    hour < 12, "Good morning, ",
    hour < 18, "Good afternoon, ",
    "Good evening, "
)
VAR todayDate = FORMAT(TODAY(), "MMMM dd, yyyy")
VAR lastUpdateDate = FORMAT(TODAY() - 1, "MMMM dd, yyyy")
RETURN 
    greetingText & LEFT(currentUser, FIND("@", currentUser) - 1) & 
    ". Welcome to the BNI Insurance Dashboard! Today is " & todayDate & 
    ". The data in this report is current as of " & lastUpdateDate & "."

Explanation of Code Components

  1. Variables Definition:

    • currentUser: Retrieves the username of the individual accessing the report.
    • hour: Obtains the current hour to determine the appropriate greeting.
    • greetingText: Uses a SWITCH statement to set the greeting based on the hour.
    • todayDate: Formats today’s date.
    • lastUpdateDate: Formats the date for yesterday to reflect the last update.
  2. RETURN Statement:

    • Combines the greetingText with the user's name and formatted dates to generate a comprehensive message.

Example Usage Scenario

This function can be utilized in a Power BI report to enhance user experience by providing personalized greetings and relevant temporal context for the dashboard's data. A user accessing the dashboard will see a message like:

Good morning, John. Welcome to the BNI Insurance Dashboard! Today is March 12, 2023. The data in this report is current as of March 11, 2023.

Conclusion

This merged DAX function employs best practices in coding, ensuring clarity and maintainability while enhancing the interactivity of the Power BI dashboard. For more advanced DAX techniques and examples, consider exploring courses available on the Enterprise DNA Platform for further professional development.

Create your Thread using our flexible tools, share it with friends and colleagues.

Your current query will become the main foundation for the thread, which you can expand with other tools presented on our platform. We will help you choose tools so that your thread is structured and logically built.

Description

This DAX measure generates a personalized greeting by combining the user's name with today's date and the last updated date of the dashboard data, enhancing the user experience in Power BI reports.