Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

I have every business date and a value, sum each value by week

wonka1234
10 - Fireball

Hi,

 

I dont have the week, I only have business date. 

 

How can I sum each business date for a given week? I need every monday.

 

expected output - 

 

dateWeekendplaceholder newly added --->new placeholderweek
1/2/2023Monday1  51/2/2023
1/3/2023Tuesday1  51/2/2023
1/4/2023Wednesday1  51/2/2023
1/5/2023Thursday1  51/2/2023
1/6/2023Friday1  51/2/2023
1/9/2023Monday0  01/9/2023
1/10/2023Tuesday0  01/9/2023
1/11/2023Wednesday0  01/9/2023
1/12/2023Thursday0  01/9/2023
1/13/2023Friday0  01/9/2023
11 REPLIES 11
DanielG
12 - Quasar

@wonka1234   - try this formula

 

datetimeadd([date],-(tonumber(datetimeformat([date],"%u"))-1),"days")

 

DanielG
12 - Quasar

You should convert your [date] to a Date data type for it to work properly though.  There is a datetime tool that can easily do that for you.  Requires a bit of renaming field and removing old field, but it is the simplest way to convert 1 date field.

RSreeSurya
9 - Comet

Hi @wonka1234 ,

 

If you could explain bit more detail, for my understanding 

 

DanielG
12 - Quasar

@wonka1234 - see attached and this datetime function page https://help.alteryx.com/20231/designer/datetime-functions

 

the formula tool I put in there breaks up the formula above to explain it a bit too (for future reference)

 

 

smoosh
8 - Asteroid

See attached workflow

 

First piece is to create a list of dates and weeks that go well into the future. 

 

Second portion is to join in your records

 

Third part aggregates to your expected values at the weekly view. 

DanielG
12 - Quasar

The formula is basically 2 parts:  

 

1.) tonumber(datetimeformat([New Date Field],"%u")) which gives you the numerical representation of day of the week (Monday = 1)

 

2.) datetimeadd([New Date Field],-('Part 1 is in here' -1),"days") which takes the number calculated in part 1 and does the math to subtracts the # of days away from Monday that you are (so the above example is this past Monday where it becomes 0 and leaves the date as it since it is already a Monday.

wonka1234
10 - Fireball

@DanielG 

 

thanks but im trying to convert the date now to  this format as a a string yyyy_mm_dd 

DanielG
12 - Quasar

I'd convert it to string with a select tool then run a formula on it replacing "-" with "_".

 

Replace([DateFieldName],"-","_")

 

I also noticed I had an error in the first pass when it was assessing it as date/time not just date.  I changed "Week" formula to include a wrap of "ToDate" to clean it up.  I fixed that and added the above to the workflow which is attached again.  Hope this helps.  

wonka1234
10 - Fireball

@smoosh  testing this now. Why did you filter the date for less then today?

Labels