Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi,
I have the following function in Power Query that returns the fiscal quarter, based on the month of the date passed.
= (AnyDate as date) =>
let
// CurrentDate = AnyDate,
CurrentMonth = if AnyDate = null then 13
else Date.Month(AnyDate),
CurrentQuarter = if CurrentMonth = 1 then "Q4"
else if CurrentMonth = 2 then "Q1"
else if CurrentMonth = 3 then "Q1"
else if CurrentMonth = 4 then "Q1"
else if CurrentMonth = 5 then "Q2"
else if CurrentMonth = 6 then "Q2"
else if CurrentMonth = 7 then "Q2"
else if CurrentMonth = 8 then "Q3"
else if CurrentMonth = 9 then "Q3"
else if CurrentMonth = 10 then "Q3"
else if CurrentMonth = 11 then "Q4"
else if CurrentMonth = 12 then "Q4"
else "Unknown"
,
CurrentFiscalQuarter = CurrentQuarter
in
CurrentFiscalQuarter
It works fine if there is a valid date is passed to the function. (Our fiscal quarters start in Feb instead of Jan).
I want the function to return "Unknown" if the date passed is null (e.g. If "AnyDate" is null, then set the CurrentMonth value to the dummy value of 13 so the CurrentQuarter goes to the "else" part.). I'm using this function in a custom column and some of the dates in the recordset is null.
However I get the following error message:
We cannot convert the value null to type Date.
I was wondering how do I check whether the date is null in the above function.
Jason
Solved! Go to Solution.
To fix the immediate issue, change
(AnyDate as date)
to
(AnyDate as nullable date)
I won't pretend to be an expert on this, but this ensures that null values of AnyDate can be handled.
See this article from Ben Gribaudo.
Regards,
Owen
Hi Owen,
thanks for your help!
Sincerely,
Jason
To fix the immediate issue, change
(AnyDate as date)
to
(AnyDate as nullable date)
I won't pretend to be an expert on this, but this ensures that null values of AnyDate can be handled.
See this article from Ben Gribaudo.
Regards,
Owen
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
112 | |
97 | |
85 | |
67 | |
59 |
User | Count |
---|---|
150 | |
120 | |
100 | |
87 | |
68 |