Calculate rows where date is less than year away - openoffice-calc

Im trying to write function for my logbook in OpenOffice calc.
I have rows that have a date in one of the cells.
Im looking for solution how to calculate rows that have date less than year from today.
I got it working by adding extra cell that calculates days from today, eg.
=DAYS(B7;TODAY())
and then use that field as COUNTIF()reference, as
=COUNTIF(C7:C2177;"<365")
But I would really like to get rid of that extra cell, as its messing up other things in that spreadsheet.
Is there a way to use variables in cell functions, or how could I get this done?

To count all dates between a year ago and a year from now:
=SUMPRODUCT(B7:B2177>TODAY() - 365, B7:B2177<TODAY() + 365)
This is adapted from https://wiki.openoffice.org/wiki/Documentation/How_Tos/Conditional_Counting_and_Summation#Tips_and_Tricks:_Items_Between_Two_Dates.

Related

PowerBI measure calculates average incorrectly - why?

To preface this, I'm fairly experienced in Excel and VBA but new to PowerBI and more than a bit confused.
I have a flat table with a [creationdate]-, [Prio] (Priority (1,2,3)) and a calculated [Days Open] column, among many irrelevant others. I need to create a chart that displays the average days a case was open by priority of the case.
To display the average "days required" per (opening-) month for the past 18 months, I created the following measure:
Prio 1 = CALCULATE(AVERAGE('SourceName'[Days Open]),'SourceName'[Prio]=1)
Then I used that as a value, and used the [creationdate] as the x-axis. (Later I changed the x-axis to a new date table linked to [creationdate] without it making a difference.) To display this as monthly averages, I used the hierarchy limited to years and months, and went down one level in the chart.
Something seemed off so I checked first in Excel, then in the data source in PowerBI and yep: The averages in the PowerBI chart are complete bullshit.
Where did I go wrong? I assume it has something to do with the date hierarchy... So I created a date table as recommended (which....why?!) and linked it. That didn't make a difference.
Meanwhile in the data panel if I filter by the date column and calculate the average with the filtered selection of numbers externally, everything works as expected, so its not like there's a date formatting issue.
Do I have to create a calculated column with something akin to
DATE(YEAR([DateColumn]),MONTH([DateColumn]),1)
, then use that as the x-axis without the hierarchy, and hope nobody cares about the day in the label? Or is there something wrong with the measure used? I'm completely lost.

Cumulative/Rolling Sum Blank Dates

I'm currently working on inventory reconciliation, and I've struggling to fill all days of the calendar with the cumulative sum of product we're currently storing:
Inventory level ($). = CALCULATE(SUM(ledger[cost]),FILTER(ALL(DimDate[Date]),DimDate[Date]<=MAX(ledger[Document Date])))
As you guys might notice it has at least 90% of all dates filled, however if we look closely to the graph, we can appreaciate March 5th of 2016 is missing just due to the fact there was no transaction during that day resulting on a blank value. However I'm trying to accomplish retrieving the previous day balance for those days with no transactions. e.g: for March 5th should have $17,038,462.32 (balance for the previous day March 4th).
I'm trying to work on another clause into the measure with functions such as EARLIER or LASTDATE, however I haven't been succesful.
Any insight or solutions works well thank you. Have a nice day.
You are using a wrong date field in your measure. Change it to the field from the Date table:
Inventory level. =
CALCULATE(
SUM(ledger[cost]),
FILTER(ALL(DimDate[Date]),DimDate[Date]<=MAX(DimDate[Date])))

Need date hierarchy for a column, otherwise DATEADD doesn't work

so I am running a DAX query where I compare 2 date columns (both have full date, no time included) and need to figure out, whether one is still valid (within range), if I add 56 days to the other - using the DATEADD function for this.
It worked before, when I had the date hierarchy in the model, seems like Power BI only accepts .[Date] notation, meaning that
DATEADD(InvoiceDueDate; 56; DAY)
won't work, but
DATEADD(InvoiceDueDate.[Date]; 56; DAY)
will work.
Still, I needed to manage relationship model in the data model and I ended up with date hierarchy lost for this column and to use it with .[Date] won't work now.
What are my options now, is there a way to return back the date hierarchy for a column? I tried googling this but came empty handed, there are results, but not entirely valid for my problem. Also DATEADD should obviously work with date column since it is a column of data type Date, but it doesn't. Would be so thankful for any help here. Thanks a lot!
Not a solution but a workaround:
InvoiceDueDate + 56
You can simply avoid using DATEADD if you don't need to add intervals other than day.

Power BI Percentage of Month passed

I would like to create a calculated column or measure that shows the time elapsed in any given month. Preferably as a percentage.
I need to be able to compare productivity (rolling total) over a month's period between different months.So creating a percentage of time passed in a month would put every month on a level playing field.
Is there a way to do this?
Or is there a better way to compare productivity between 2 months on a rolling basis?
EDIT
I am graphing sales on a cumulative basis. Here is a picture of my graph to demonstrate.[][
Ideally I would like to be able to graph another person's sales on the same graph for a different month to compare.
The problem is each month is different and I don't think power bi allows much customization of the axes.
So I figured a potential solution would be to convert months to percentages of time passed, create two separate graphs and place them on top of each other to show the comparison of sales.
Using percentages doesn't sound right here: one person's "productivity" in February will appear lower than another person's productivity in March just because February has 3 less days.
Just use [Date].[Day].
To answer the original question (even though it shouldn't be used for this), month progress percentage calculated column:
MonthProgress% =
var DaysinMonth = DAY(
IF(
MONTH(MyTable[date]) = 12,
DATE(YEAR(MyTable[date]) + 1,1,1),
DATE(YEAR(MyTable[date]), MONTH(MyTable[date]) + 1, 1)
) - 1
)
return MyTable[date].[Day]/DaysinMonth*100
Also check DAX functions PARALLELPERIOD and DATEADD.
This is the solution I settled on.
I customized the ranges for the x and y axes so they match.
For the y-axis, I simply put the range from 0 to 50+ our highest month.
For the x-axis, I created a column with the DAY function so I got a number assigned to each day of the month which allowed me to manually set the chart range from 0 to 31. I have asked another question on how to only get workdays.

PowerBI - Week Number on X-Axis

I have a line graph in PowerBI and in my date dimension I have the Week Number for every date (note that this is a custom week number with the week starting on Friday).
Whenever I put it on a the x-axis, PowerBI groups all the weeks together, regarless of year... so Week 1 of year 2015 will be grouped together with Week 1 of 2016...
I think to myself: "Ok, no problem, I'll just add the Year after every week number so I'll have 1-2016, 2-2016, and so on."
Well PowerBI sees this concatenation as a string value so when I put that on the graph, it goes
1-2016, 1-2017, 2-2016, 2-2017, 3-2016, 4-2016, and so on....
I've tried sorting the new column by the old week number column, but it does the same thing. Any suggestions on how to accomplish this?
You're on the right track. I recommend a separate (hidden) sort column that sorts alphabetically (i.e. year first, then 2 digit week). In other words, 1-2016 = 201601.
This way, all the weeks for 2016 sort before the weeks for 2017, and the weeks sort in the right order too. (A 1 digit week would mean 20161 will be followed by 201610, which you don't want either.)