Unlock Weather Insights: How You Can Use Power BI with OpenWeatherMap — Part 7
We have created some basic measures to display temperatures in a formatted style. We have more measures to create. The measures used in this dashboard a simple measures and provide formatted information.
Creating Air Quality Measure
The next measure we will create is the “Air Quality” measure. Follow the steps below to create this measure.
- Select the _All_Measures table.
- Select the “New Measure” button in the Table Tools ribbon. Or you can right click on the table and select New Measure from the pop-up menu that appears.
- Enter the following code into the formula bar that appears replacing any existing text in that formula bar. Use Shift+Enter to create an empty line in the formula bar to enter the measure over multiple lines. I do this to make it easier to read measures, especially complex measures.
Air Quality =
"The Air Quality is " &
MIN(
'Air Quality'[Quality Description]
)
- Click on the commit button or press enter to save the measure.
Creating Temperature measure
This measure will display the current temperature formatted in degrees Celsius. Remember to change the C to an F if you are using imperial units.
- Select the _All_Measures table.
- Select the “New Measure” button in the Table Tools ribbon. Or you can right click on the table and select New Measure from the pop-up menu that appears.
- Enter the following code into the formula bar that appears replacing any existing text in that formula bar. You can copy and paste the code into the formula bar to save typing if that is useful for you!
Temperature =
FORMAT(
MIN(
'Current Weather'[temp]
),
"#0" & UNICHAR(176)&"C"
)
- Remember to click on the commit button or press enter to save the measure.
Creating Weather Image URL measure
This measure will dynamically return the URL from the Wallpaper table that holds the URLs for all the images used as backgrounds in the dashboard. The measure will return the URL that matches the current weather in the report. Please note I do not have every type of weather in the table. I only have URLs to match the weather that I have come across whilst using the dashboard. If the table does not have the current weather, it will return an empty string, which will cause a grey background to be shown. If this occurs, then the wallpaper table will need to be updated with a new weather URL and description.
- Select the _All_Measures table.
- Select the “New Measure” button in the Table Tools ribbon. Or you can right click on the table and select New Measure from the pop-up menu that appears.
- Enter or copy and paste the following code into the formula bar that appears replacing any existing text in that formula bar.
Weather Image URL =
VAR CurrentWeather = MIN('Current Weather'[weather.description])
RETURN
CALCULATE(
MIN(Wallpaper[URL]),
FILTER(
Wallpaper,
Wallpaper[Weather] = CurrentWeather
)
)
- Click on the commit button or press enter to save the measure.
Creating Weather Unsplash Credit
According to the license for using Unsplash images, users must credit the photographer. So I created a column in the Wallpaper that holds the image credit text from the Unsplash website. This text will appear in a window when you download an image. This measure will return the credit text that for the weather that matches the current weather. It is very similar to the Weather Image URL measure. It simply returns the information from a different column. To create the measure, follow the following steps.
- Select the _All_Measures table.
- Select the “New Measure” button in the Table Tools ribbon. Or you can right click on the table and select New Measure from the pop-up menu that appears.
- Enter or copy and paste the following code into the formula bar that appears replacing any existing text in that formula bar.
Weather Unsplash Credit =
VAR CurrentWeather = VALUES('Current Weather'[weather.description])
RETURN
CALCULATE(
MIN(Wallpaper[Unsplash Credit]),
FILTER(
Wallpaper,
Wallpaper[Weather] = CurrentWeather
)
)
- Remember to click on the commit button or press enter to save the measure.
Creating Wind Phrasing measure
The last measure we need to create is a simple measure to return the text for the wind Speed based on the Beaufort scale. The measure will update the text to make it read nicer.
- Select the _All_Measures table.
- Select the “New Measure” button in the Table Tools ribbon. Or you can right click on the table and select New Measure from the pop-up menu that appears.
- Enter or copy and paste the following code into the formula bar that appears replacing any existing text in that formula bar.
We have created all the measures we will use in this dashboard. In the next part, we will begin adding visuals to the report canvas. But we will add the background image to the dashboard last of all to make it easier to add the other visuals.
Wind Phrasing =
SWITCH(
MIN('Current Weather'[Wind Speed Description]),
"Calm","calmly",
"Light Air","light air",
"a " & LOWER(MIN('Current Weather'[Wind Speed Description]))
)
- Don’t forget to click on the commit button or press enter to save the measure.
We have created all the measures we will use in this dashboard. In the next part, we will start adding visuals to the report canvas. But we will add the background image to the dashboard last of all to make it easier to add the other visuals.
Don’t forget to subscribe to
and join our Power BI community