Function: If and statement with numbers and dates

joslaz

Board Regular
Joined
May 24, 2018
Messages
76
Hey!

Unfortunatelly, I am still not good at defining own functions in power query.
May someone of you can help me.

I have the following table:

Date - Value
01.01.2018 0.75

The aim is to get for weekdays a maximum value of 0.75.
So if the value ist 0.76 and its mo, it should get a value of 0.75
For the weekend the maximum number ist 0.8.

Of course, these could be management with some conditional columns but I am looking for a more elegent way like a own function.

Maybe someone have any idea.



Best regards
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
I believe this will do what you want.

Code:
 if Date.DayOfWeek([Date], Day.Monday) < 5 then if [Amount] <= .75  then [Amount] else .75 else if Date.DayOfWeek([Date], Day.Monday) >= 5  then if [Amount] <= .8 then [Amount] else .8 else 0

That will assign a number 0-6 to the day of the week it is. Sat/Sun are 5/6. I told it to start Monday at 0.
 
Upvote 0
It works perfect! Thanks a lot!

Do you know, how to adapt the code on a duration type of values?
Like: if Date.DayOfWeek([Date], Day.Monday) < 5 then if [Amount] <= 00.07:45:00 then [Amount] else 00.07:45:00 else if Date.DayOfWeek([Date], Day.Monday) >= 5 then if [Amount] <= 00.08:45:00 then [Amount] else 00.08:45:00 else 0


 
Upvote 0
Thanks a lot!

But this approach doesnt work:

if Date.DayOfWeek([Date], Day.Monday) < 5 then if [Amount] <= #duration (0,8,45,0) then [Amount] else #duration (0,8,45,0) else if Date.DayOfWeek([Date], Day.Monday) >= 5 then if [Amount] <= #duration (0,9,45,0) then [Amount] else #duration (0,9,45,0) else 0
Does anyone know, where the problem is?

 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top