We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Hello All,
I'm looking for assistance to convert the following IF functions in M Language.
Regards,
Jajati Dev
Solved! Go to Solution.
Hi, @JajatiDev
assuming your initial step in the PQ editor is the #"ChangedType" then the M code will be:
#"AddAgeing" = Table.AddColumn(#"ChangedType", "Ageing", each if [ReceiveDate]=DateTime.LocalNow() then 0 else need to use custom func equivalent to networkdays, DateTime.Date(DateTime.LocalNow())), type number)
this blog will help you: https://community.fabric.microsoft.com/t5/Community-Blog/Date-Networkdays-function-for-Power-Query-a...
for the rest:
#"AddAgeGroup" = Table.AddColumn(#"AddAgeing", "Age Group", each
if [Ageing]>=0 and [Ageing]<=5 then "[0 - 5]"
else if [Ageing]>=6 and [Ageing]<=10 then "[6 - 10]"
else if [Ageing]>=11 and [Ageing]<=20 then "[11 - 20]"
else if [Ageing]>=21 and [Ageing]<=30 then "[21 - 30]"
else if [Ageing]>=31 and [Ageing]<=60 then "[31 - 60]"
else if [Ageing]>=61 and [Ageing]<=90 then "[61 - 90]"
else "[ > 90]"
)
in
#"AddAgeGroup"
Proud to be a Super User!
Hi, @JajatiDev
assuming your initial step in the PQ editor is the #"ChangedType" then the M code will be:
#"AddAgeing" = Table.AddColumn(#"ChangedType", "Ageing", each if [ReceiveDate]=DateTime.LocalNow() then 0 else need to use custom func equivalent to networkdays, DateTime.Date(DateTime.LocalNow())), type number)
this blog will help you: https://community.fabric.microsoft.com/t5/Community-Blog/Date-Networkdays-function-for-Power-Query-a...
for the rest:
#"AddAgeGroup" = Table.AddColumn(#"AddAgeing", "Age Group", each
if [Ageing]>=0 and [Ageing]<=5 then "[0 - 5]"
else if [Ageing]>=6 and [Ageing]<=10 then "[6 - 10]"
else if [Ageing]>=11 and [Ageing]<=20 then "[11 - 20]"
else if [Ageing]>=21 and [Ageing]<=30 then "[21 - 30]"
else if [Ageing]>=31 and [Ageing]<=60 then "[31 - 60]"
else if [Ageing]>=61 and [Ageing]<=90 then "[61 - 90]"
else "[ > 90]"
)
in
#"AddAgeGroup"
Proud to be a Super User!
Hi, thanks for responding.
I have been working on the ageing calculation. The issue with the output is it's considering all days including the weekends between receive_data and the current date. I need to exclude weekends.
if [receive_date] = DateTime.LocalNow() then 0 else
DateTime.Date(DateTime.LocalNow()) - [receive_date]
By now I have got a good hang of IF & AND. Hoping to improve my understanding on others as well.
Proud to be a Super User!
Hi,
Here is the customer column calculation I have put in place to calculate ageing.
List.Sum({0} & List.Transform(List.Dates(Date.AddDays( [hp_receive_date], 1), Duration.Days(Date.From(DateTime.LocalNow()) - [hp_receive_date]) , #duration(1, 0, 0, 0)), each if Date.DayOfWeek(_, Day.Monday) < 5 then 1 else 0))
Allow me time to work through it because I'm a beginner. and I'm using the add column >> customer column option to provide the inputs.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 5 | |
| 3 | |
| 3 | |
| 2 | |
| 2 |
| User | Count |
|---|---|
| 11 | |
| 10 | |
| 7 | |
| 6 | |
| 5 |