Power Pivot - Count Until

hayden

Board Regular
Joined
Sep 23, 2005
Messages
188
I have a column of data created through prior if statements that contain either a value of zero, or a value greater than zero. I'm trying to create a new column that will count the days until the value is greater than 1. Below is an example of the data (Value column) and the result I'd like (count). I have a feeling this is a calculate with distinct count and some filter, but I can't seem to craft something that works.

In excel, I would simply start a formula in row 2 that was if(value>0,0,Count from row above + 1).

ValuesCount
01
02
03
04
05
0.9870
01
02
.990
 
Thank you Rory.

That returns the last date that had a contents of 98% or more. Is it possible to modify this to return the date that the maximum percent contents occurred during that year? (i.e. it currently returns 8/18/2001, the last date that had a contents of at least 98%, I'm hoping to return 6/4/2001, which is the date with the highest contents during 2001.
Screenshot 2023-12-11 090052.png


I wonder if I could create a group by table with the maximum dates, then filter by those dates? I've saved an updated version of the sample file here:
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
That returns the last date that had a contents of 98% or more
Well, that is what you asked for, so... ;)

Is it simply the max value that occurred at any point during that year?
 
Upvote 0
Thanks for the patience as I try and ask my question again.

We know the minimum reservoir contents for the entire period of record occurred on March 21, 2003.

I want to return the date that the reservoir contents was last at its maximum for the year, but only if the percent full associated with that maximum value is over 98%.
 
Upvote 0
I think I got it!
Created a new table called FullPct that returns the Year and the maximum percentage full using groupby.

In my Daily Table:
Added a column for the Year [WaterYr] using Date.Year....
Added a column for PctFull with this:
Power Query:
=CALCULATE(FIRSTNONBLANK(FullPct[FullPct],1),FILTER(FullPct,FullPct[WaterYr]=Daily[WaterYr] && FullPct[FullPct]=Daily[PercentFull]))

This returns the maximum percentage full by year on the date it occurred, otherwise its blank.

Modified the measure that Rory helped with to:
Power Query:
StartDate:=VAR startFrom = [EndDate] RETURN maxx(FILTER(Daily,Daily[PctFull]>=[UserPct] && Daily[Date]<=startFrom),Daily[Date])

@RoryA - Thanks for your patience and help.
 
Upvote 0
Well, when I moved out of my sample data and into my main data it didn't work...

Here is what I finally settled on.
Create a query which returns a table of year and max percentage each year using groupby.
Merge this query with the daily query based on Year and Percentage (this is the multiple criteria query).
Expand the resulting table to just keep the date. Now I have a table with the year, max percentage, and date it occurred.

Finally, write a measure for this new table that calculates the max with filter and the && symbols.
Power Query:
CriticalStartDate:=CALCULATE(MAX(MaxPct[DailyTable.Date]),FILTER(MaxPct,MaxPct[DailyTable.Date]<=DailyTable[CriticalEndDate] && MaxPct[MaxPct]>=TblUserInput[CriticalFullPercentage]))
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,976
Members
449,095
Latest member
Mr Hughes

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