Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon'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.
Hello,
I'm working with public data from the German Weather Service (DWD) for a project for my university. I have monthly data from January 1881 to March 2023 for the average air temperature, sunshine duration, and precipitation for the federal states and germany as a whole. The data is connected to a date table in which I have implemented a date hierarchy. I have created a line and stacked column chart for the column 'Germany' in the 'air_temperature_mean' table. However, as the average temperature for the year 2023 is distorted due to data only being available for three months, I aimed to develop a measure that identifies the latest year for which data for all 12 months is available, which can be used in a measure to calculate the average temperature. Consequently, I have written the following measure:
In my opinion, this measure works as intended, but just to be sure, I asked ChatGPT to write another measure for the same purpose, as I have relatively little experience with DAX:
Here is a link to download the PowerBI report:
Solved! Go to Solution.
I noticed that i never posted the solution I found to my problem. But perhaps other have similar problems and can therefore benefit from the following code:
last meteorologically completed year =
var completedYears=
SELECTCOLUMNS(
FILTER(
ADDCOLUMNS(
DISTINCT(
SELECTCOLUMNS('DateTable',"year",'DateTable'[Date].[Year])
),
"completed_Year?",
CALCULATE(
COUNTX('DateTable','DateTable'[Date].[Month])
)=12
),
[completed_Year?]=TRUE()
),
"year",
[year]
)
return DISTINCT(
SELECTCOLUMNS(
SUMMARIZE(
completedYears,
[year],
"Max",
MAXX(
completedYears,
[year]
)
),
"last_meteorologically_completed_year",
[Max]
)
)
Note that I changed some table and column names to increase code readability.
I noticed that i never posted the solution I found to my problem. But perhaps other have similar problems and can therefore benefit from the following code:
last meteorologically completed year =
var completedYears=
SELECTCOLUMNS(
FILTER(
ADDCOLUMNS(
DISTINCT(
SELECTCOLUMNS('DateTable',"year",'DateTable'[Date].[Year])
),
"completed_Year?",
CALCULATE(
COUNTX('DateTable','DateTable'[Date].[Month])
)=12
),
[completed_Year?]=TRUE()
),
"year",
[year]
)
return DISTINCT(
SELECTCOLUMNS(
SUMMARIZE(
completedYears,
[year],
"Max",
MAXX(
completedYears,
[year]
)
),
"last_meteorologically_completed_year",
[Max]
)
)
Note that I changed some table and column names to increase code readability.
@Fechner , I am assuming you have created a date in you table using month year and then join it using date with date table
As per me simple Avg
AVERAGE(air_temperature_mean[Deutschland])
or
Avg of month=
AVERAGEX(Values(Date[Month Year]), calculate(AVERAGE(air_temperature_mean[Deutschland])))
Should work
You can try YTD measure, if needed
YTD Sales = CALCULATEAVERAGE(air_temperature_mean[Deutschland]),DATESYTD('Date'[Date],"12/31"))
If this does not help
Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.
Thank you for your anwser. Perhaps I was not precise enough in my previous message. The measure should calculate the average temperature from January 1881 until the latest year for which all monthly data is available, which in my case is 2022. However, once the missing monthly data for 2023 is added, it should be included in the calculation as well.
Here is a link to download the PowerBI report:
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
119 | |
78 | |
58 | |
52 | |
46 |
User | Count |
---|---|
170 | |
117 | |
63 | |
58 | |
51 |