ZN(LOOKUP(SUM([Profit]),0))
IF [Profit no gaps] >= 0 THEN NULL ELSEIF LOOKUP([Profit no gaps],-1) >= 0 THEN MIN([Order Date]) ELSE PREVIOUS_VALUE(#1/1/18#) END
LOOKUP([Profit no gaps],1)
IF [Profit no gaps] >= 0
THEN NULL
ELSEIF [Next Profit Value] >= 0
THEN MIN([Order Date])
ELSE PREVIOUS_VALUE(#1/1/18#)
END
DATEDIFF('day', [Start Date], [End Date]) + 1
IF [Days in Streak] = 1 THEN
WINDOW_SUM(
IF [Days in Streak] = 1
THEN COUNTD([Order Date])
END
)
ELSEIF [Days in Streak] = 2 THEN
WINDOW_SUM(
IF [Days in Streak] = 2
THEN COUNTD([Order Date])
END
)
ELSEIF [Days in Streak] = 3 THEN
WINDOW_SUM(
IF [Days in Streak] = 3
THEN COUNTD([Order Date])
END
)
ELSEIF ...
END / [Days in Streak]
Note: The calculated fields [# of Streaks] and [Keep only one date per streak group] must include a condition for every possible number of days in a streak. For more explanation on why see the article Using an Aggregate Field to Define the Level of Detail in a Table Calculation
MIN([Order Date]) = WINDOW_MIN(IF[Days in Streak] = 1 THEN [Start Date] END)
OR MIN([Order Date]) = WINDOW_MIN(IF[Days in Streak] = 2 THEN [Start Date] END)
OR MIN([Order Date]) = WINDOW_MIN(IF[Days in Streak] = 3 THEN [Start Date] END)
OR ...
""
Creating the prep flow is more upfront work, but building the views from the prep output is much simpler compared to building the views with table calculations. The "Grouping Consequtive days.tflx" prep flow demonstrates the following steps and can be downloaded from the right-hand pane.
IF [Profit] < 0
THEN 'negative'
ELSE 'positive'
END
{ PARTITION [Category], [Condition] : { ORDERBY [Order Date] ASC : RANK_DENSE()}}
[Row Number] + 1
IF ISNULL(DATEDIFF('day', [Order Date-1], [Order Date]))
OR DATEDIFF('day', [Order Date-1], [Order Date]) > 1
THEN [Order Date]
END
{ PARTITION [Category], [Condition] : { ORDERBY [Start Date] ASC: RANK_DENSE()}}
[Row Number] - 1
IF ISNULL(DATEDIFF('day', [Order Date], [Order Date-1]))
OR DATEDIFF('day', [Order Date], [Order Date-1]) > 1
THEN [Order Date]
END
{ PARTITION [Category], [Condition] : { ORDERBY [End Date] ASC: RANK_DENSE()}}
DATEDIFF('day', [Start Date],[End Date])+1
The prep flow output includes start dates for groupings that meet the condition (has negative profit) and groupings that do not meet the condition. A filter could be added in the "Row Number" clean step to keep only [Condition]='negative' to exclude groupings that do not meet the condition, otherwise the [Condition] filter needs to be added to the view.
001456688
1685 KB
989 KB

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.