Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
I have a table that includes monthly transaction data across multiple projects. Each month there are values for "actuals" and "forecasts". I would like to create a new column using power M query or DAX custom column features in PowerBI. This column should equal the value in either the "Actual" or "Forecast" column based on the following rule.
The 2nd Friday of the month is the trigger to switch from using "forecast" to "actuals" in the prior month. So, it should use the "forecast" value for September 2020 until the 2nd Friday in October 2020. After that, it should use the "Actual" value.
In the same table, I have a "year" column, "month" column, and a "date_key" column in the format of yyyymmdd. Example below.
So assuming the date is October 21, beyond the 2nd Friday of October, so it should use actuals for Sept and Forecast for Oct...
Project | Date_Key | Actual | Forecasts | Custom | ||
1 | 20200701 | 10 | 20 | 10 | ||
1 | 20200801 | 10 | 20 | 10 | ||
1 | 20200901 | 10 | 20 | 10 | ||
1 | 20201001 | 10 | 20 | 20 | ||
2 | 20200901 | 10 | 20 | 10 | ||
2 | 20201001 | 10 | 20 | 20 | ||
2 | 20201101 | 10 | 20 | 20 |
Has the problem been solved? If so, you may accept the appropriate post as the solution or post your own solution to help other members find it quickly. Thanks.
Best Regards,
Community Support Team _ Jing Zhang
Hi @ScottyR ,
Try the following code:
if #date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()),1)
<=
#date(
Number.FromText(
Text.Start(Number.ToText([Date_Key]),4)),
Number.FromText(
Text.Start(Text.End(Number.ToText([Date_Key]),4),2)),
1 ) then [Forecasts] else if #date(
Number.FromText(
Text.Start(Number.ToText([Date_Key]),4)),
Number.FromText(
Text.Start(Text.End(Number.ToText([Date_Key]),4),2)),
Number.FromText(
Text.End(Number.ToText([Date_Key]),2)) ) <
Date.StartOfWeek(#date(Date.Year( DateTime.LocalNow() ),Date.Month(DateTime.LocalNow()),14),Day.Friday) then [Actual] else [Forecasts]
Be aware that you may need some adjustements because the current date is already afte the second friday.
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsUser | Count |
---|---|
125 | |
106 | |
99 | |
63 | |
62 |
User | Count |
---|---|
135 | |
116 | |
101 | |
71 | |
61 |