Forum Discussion
Anonymous
5 years agoNot applicable
Need cumulative sum with condition
Hi All, Hope everyone is well and safe in this pandemic. Iam new to Power BI and working on few calculations that need your help. As shown above i have week and weekly confirmed cases ...
- 5 years ago
Hi Anonymous ,
Try this:
StartWeek = VAR ThisWeek = MAX ( districts[Week] ) VAR LastWeek = ThisWeek - 1 VAR ThisTrend = [Up/Down Trend Test] VAR LastTrend = IF ( ThisWeek > 1, CALCULATE ( [Up/Down Trend Test], districts[Week] = LastWeek ) ) RETURN IF ( ThisTrend <> LastTrend, ThisWeek )consecutive count = VAR CalStartWeek = MAXX ( FILTER ( ALLSELECTED ( districts[Week] ), districts[Week] <= MAX ( districts[Week] ) ), [StartWeek] ) VAR ThisWeek = MAX ( districts[Week] ) RETURN CALCULATE ( COUNTROWS ( districts ), districts[Week] >= CalStartWeek && districts[Week] <= ThisWeek )Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Icey
Community Support
5 years agoHi Anonymous ,
Try this:
StartWeek =
VAR ThisWeek =
MAX ( districts[Week] )
VAR LastWeek = ThisWeek - 1
VAR ThisTrend = [Up/Down Trend Test]
VAR LastTrend =
IF (
ThisWeek > 1,
CALCULATE ( [Up/Down Trend Test], districts[Week] = LastWeek )
)
RETURN
IF ( ThisTrend <> LastTrend, ThisWeek )
consecutive count =
VAR CalStartWeek =
MAXX (
FILTER (
ALLSELECTED ( districts[Week] ),
districts[Week] <= MAX ( districts[Week] )
),
[StartWeek]
)
VAR ThisWeek =
MAX ( districts[Week] )
RETURN
CALCULATE (
COUNTROWS ( districts ),
districts[Week] >= CalStartWeek
&& districts[Week] <= ThisWeek
)
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.