Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreShape the future of the Fabric Community! Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions. Take survey.
In Power BI, I have a table that counts the number of projects that need to be completed by their due date. However, there is a need for projects that are not completed within the specified month to automatically move to the next month. For example, a project scheduled for January, if not completed by the due date, should automatically move to February, and so on, until I update it in my data source. Is there a way to do this in Power BI?
Solved! Go to Solution.
Hi @amaral_diego ,
I update the measure, you can try this one.
AjustarData =
VAR _Today =
TODAY ()
VAR _DATEDIFF =
DATEDIFF ( 'Table'[Termino], TODAY (), DAY )
VAR _DATE1 =
EOMONTH ( TODAY (), -1 ) + DAY ( 'Table'[Termino] )
VAR _DATE2 =
EOMONTH ( _DATE1, 0 ) + DAY ( 'Table'[Termino] )
RETURN
IF (
'Table'[Status] = "Complete",
'Table'[Termino],
IF (
'Table'[Termino] < _Today,
IF ( _DATE1 < TODAY (), _DATE2, _DATE1 ),
'Table'[Termino]
)
)
Result of my sample is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
I also have tried with M language, with this function below
(AjustarData as nullable date) as nullable date =>
let
DataAtual = DateTime.LocalNow(),
NovaData = if AjustarData <> null and AjustarData < DataAtual then Date.AddMonths(AjustarData, 1) else AjustarData
in
NovaData
Then I go to "add column" and then "Invoke Custom Function"
So I select the function I created and then it gives me the option to enter a date, or select a column. If I go by the column or select the column that has the end date "Termino", it creates the column but without being in the date format and with "Error" in all the lines. This is the code that is in the column.
= Table.AddColumn(#"Erros Substituídos", "Nova Data - Conclusão", each fnAjustarDataConclusao([Termino]))
Is there any way to adjust this, so that it creates the dates for the following month automatically?
Hi @amaral_diego ,
Are you trying to delay the end date of a project whose due status is not yet Complete by one month?
Please try code as below to create a calculated column.
AjustarData =
VAR _DATEDIFF = DATEDIFF('Table'[Termino],TODAY(),Day)
RETURN
IF('Table'[Status] = "Complete",'Table'[Termino],IF('Table'[Termino]<TODAY(),EOMONTH(TODAY(),-1)+DAY('Table'[Termino]),'Table'[Termino]))
Result of my sample is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, with this code is almost helped me, it worked to send all projects to the next moth, but, for example, now I've 6 projects delayed from september that is now send to october, although I've one deleyed in october and he still in octorber, is possible to sent him do november?
If not, it's ok, I'll acept thi one as solution, thanks a lot.
Hi @amaral_diego ,
I update the measure, you can try this one.
AjustarData =
VAR _Today =
TODAY ()
VAR _DATEDIFF =
DATEDIFF ( 'Table'[Termino], TODAY (), DAY )
VAR _DATE1 =
EOMONTH ( TODAY (), -1 ) + DAY ( 'Table'[Termino] )
VAR _DATE2 =
EOMONTH ( _DATE1, 0 ) + DAY ( 'Table'[Termino] )
RETURN
IF (
'Table'[Status] = "Complete",
'Table'[Termino],
IF (
'Table'[Termino] < _Today,
IF ( _DATE1 < TODAY (), _DATE2, _DATE1 ),
'Table'[Termino]
)
)
Result of my sample is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
It worked, thanks a lot!
Remember that MAX( ) can take two parameters, not just one.
Hi,
Here’s a general approach to get you started
Add a Status Column: Ensure your data source has a column indicating whether a project is completed or not.
Create a Calculated Column
Here’s an example:
AdjustedDueDate =
IF(
[Status] = "Completed",
[DueDate],
EOMONTH([DueDate], 1) + 1
)
3. Create a Measure for Counting Projects
Here’s an example measure:
ProjectsDueThisMonth =
CALCULATE(
COUNTROWS(ProjectsTable),
FILTER(
ProjectsTable,
YEAR([AdjustedDueDate]) = YEAR(TODAY()) &&
MONTH([AdjustedDueDate]) = MONTH(TODAY())
)
)
Proud to be a Super User! | |
I've tried this way below
Created this Calculated Column
DataAjustada =
VAR DataInicial = f_Projetos[Termino]
VAR MesesAdicionados = DATEDIFF(DataInicial, TODAY(), MONTH) + 1
RETURN
IF(
DataInicial < TODAY(),
EDATE(DataInicial, MesesAdicionados),
DataInicial
)
and this measure below
ProjetosAtrasadosPorMes =
CALCULATE(
COUNTROWS(
FILTER(
f_Projetos,
f_Projetos[Termino] < TODAY() &&
f_Projetos[Status] <> "Completo" &&
f_Projetos[Status] <> "Despriorizado" &&
f_Projetos[DataAjustada] >= EDATE(f_Projetos[Termino], 1)
)
),
USERELATIONSHIP(d_Calendario[Date], f_Projetos[DataAjustada])
)
It's almost working, the thing is, it showing the information on November column,
In my case, it should appear in October. It should move the overdue project to the following month, and here in my case the overdue projects are from September.
Could help me to solve this
Can you update with this
Here’s a revised version of your calculated column:
DataAjustada =
VAR DataInicial = f_Projetos[Termino]
VAR MesesAdicionados = DATEDIFF(DataInicial, TODAY(), MONTH) + 1
RETURN
IF(
DataInicial < TODAY(),
EOMONTH(DataInicial, MesesAdicionados - 1) + 1,
DataInicial
)
Proud to be a Super User! | |
Hi, I’ve tried using this code, but unfortunately, the issue persists. It continues to show the information for November instead of October.
Hi @amaral_diego ,
I think you may use multiple tables in your calculation and your data model is complex with inactive relationships.
Here I suggest you to show us your data model and what tables look like. You can share a sample file with us and show us a screenshot with your error or the result you want. This will make it easier for us to find the solution.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
I'm sent to you the screenshot's of the datamodel in two parts, the "Termino" column is the date the project should be completed.