Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi,
I am new to Power BI. I have been having a hard time trying to replicate this formula in Power BI:
=IF([@[Return Approved Date]]="","NO APPROVAL DATE",ROUNDDOWN($BC$1-[@[Return Approved Date]],0))
where $BC$1 is TODAY()
I added a custom column using this formula
However, the value of that returns Error only.
Please help..
Solved! Go to Solution.
Hi @Anonymous ,
Is today a column on your data model? you need to use a DATEDIFF formula that in M language is DURATION.
check the formulas on the link below:
https://docs.microsoft.com/en-us/powerquery-m/duration-functions
Also if you want to pick todays date you need to use
DateTime.LocalNow()
Try the following code:
if [Return Approved Date] = null then "No Approved date" else Duration.Days (Duration.From( #date(Date.Year(DateTime.LocalNow()), Date.Month(DateTime.LocalNow()), Date.Day(DateTime.LocalNow()) )
- [Return Approved Date]))
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsHi @Anonymous ,
Using the Today column will also work the only question is that if you are using that column only for this calculation this will have an increase of data in your model, so there is no need to have this additional column on the model since you can do the calculation to make use of the today column redo the formula to:
if [Return Approved Date] = null then "No Approved date" else Duration.Days (Duration.From( [Today] - [Return Approved Date]))
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsHi @Anonymous ,
Is today a column on your data model? you need to use a DATEDIFF formula that in M language is DURATION.
check the formulas on the link below:
https://docs.microsoft.com/en-us/powerquery-m/duration-functions
Also if you want to pick todays date you need to use
DateTime.LocalNow()
Try the following code:
if [Return Approved Date] = null then "No Approved date" else Duration.Days (Duration.From( #date(Date.Year(DateTime.LocalNow()), Date.Month(DateTime.LocalNow()), Date.Day(DateTime.LocalNow()) )
- [Return Approved Date]))
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsHi @MFelix , do you mind if i ask you to help me understanding the code below:
Duration.Days (Duration.From( #date(Date.Year(DateTime.LocalNow()), Date.Month(DateTime.LocalNow()), Date.Day(DateTime.LocalNow()) )
like can you please how it works step by step?
thanks!
This actually worked. Thank you! Before I press the accept as solution. May i know if using Today column will work too? I have created a column for today which is
DateTime.LocalNow()
Hi @Anonymous ,
Using the Today column will also work the only question is that if you are using that column only for this calculation this will have an increase of data in your model, so there is no need to have this additional column on the model since you can do the calculation to make use of the today column redo the formula to:
if [Return Approved Date] = null then "No Approved date" else Duration.Days (Duration.From( [Today] - [Return Approved Date]))
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsHello @MFelix Can you also explain to me the logic behind the code below:
Duration.Days (Duration.From( #date(Date.Year(DateTime.LocalNow()), Date.Month(DateTime.LocalNow()), Date.Day(DateTime.LocalNow()) )
I just need more understanding how it works.
Thanks!
User | Count |
---|---|
76 | |
75 | |
46 | |
31 | |
27 |
User | Count |
---|---|
99 | |
91 | |
51 | |
49 | |
45 |