Today here, tomorrow DAX

Formulated in kind of a raw way, Power BI splits its coding part in terms on languages into frontend with DAX and backend with M. The M query language is needed to prepare various incoming data sources. All preprocessing steps are coded sequentually. DAX is then used to adapt to circumstances that cannot be done beforehand with M. Stuff that either has to adapt to the user or time for example. Something that falls into that category is the adoption of titles of elements in the frontend to the current year. The easiest way to get the current year can be fetched through DAX internal functions. With this function, a measure called currentYear is calculated dynamically with the YEAR function. This function expects as input a value of type date. A way to obtain both, a value of type date and dynamically an actual value would be with the DAX internal function TODAY. Another alternative would be through the NOW, which adapts even to time. In this case, that information is not needed and TODAY corresponds to the actual use case.

              
                currentYear = YEAR(TODAY())
              
            

With M, the default use case is to create tables that are then displayed in the PowerBI frontend through various kinds of charts. DAX on the other hand calculates among other things so called measures. This dynamically calculated measure currentYear can then be used further to create a text measure. A measure in DAX is created in kind of a clicky way by mouse. By right click on the corresponding table the measure can be added a line on the top of the front end arises. There the DAX formula has to be written. In this case here, a goLives variable of type text is dynamically written and can be further used by a frontend element in its title as the third step in this process then.

              
                goLives = "Go-lives" & xxx[lastYear] & " vs. " & xxx[currentYear]
              
            

An important fact here is to convert the variable to a specific type in PowerBI, which again is a clicky task. The problem is described in this thread thread. The created text measurement has to be of type text. Otherwise it can not selected by the element later on as the last step of that process. Here it has to be changed from decimal to text type.

Type setting of text measurement in PowerBI to be used as title in front end element
Fig.1 - Set type in PowerBI to use text measure in titles of front end elements.

Through kind of a clicky procedure described in figure 2, the title of a visual element can be described dynamically through a measure in a table. To finally create the dynamic title, an element has to be selected first by through clicking on it. The properties section on the right hand side offers an option called Visualizations and Titel.

Overview of visualization options for frontend element Drawing options of visualization element General drawing options of visulization element
Fig.2 - Visualization options for frontend element with General (Allgemein) options to be selected where Title can be found and a function fx can be choosen as source.

By using the fx option, the a measure from the table can be selected as shown in figure 3.

Selection of measure from table
Fig.3 - Selection of a specific measure from a table reflecting the dynamic title to be shown on the element.

As a result of all of those settings, the title of the visual element is adapting dynamically to date, in this case to year, as the measure is a dynamically calculated by refreshing the page. Finally an example of this title is shown in figure 4.

Dynamically adapting title
Fig.4 - Dynamic title adapting to year in visual element.