Moving total which uses two calculated fields and also uses its previous value-Spotfire - spotfire

Hi folks I am new to Spotfire and having difficulty in replicating one of the formulas from Excel to spotfire.
Sample Data
Sample data here(excel)
https://docs.google.com/spreadsheets/d/1KSdrIYKlRYG9c3wIM3NwQcLP_Ob8Z2UZ5Cjrdjy8UO8/edit?usp=sharing
and I am trying to replicate the column [Steady Repay-Option Scenario]
Formula used in excel
=IF(B6-IF(C3>0,C2,0)>0,B6-IF(C3>0,C2,0),0)
the above is the formula I have in excel where subsequent columns are calculated by using the previous value and the current values from columns [Monthly impact on cash] and [running total]
This is the formula I have created in spotfire:
if((Sum([Scenario opening balance]) over (allPrevious([Document_Date_Number])) - (If(Sum([Rolling_total_cash_calculated]) over (AllPrevious([Document_Date_Number]))>0,Sum([Monthly_impact_on_cash_calculated]) over (AllPrevious([Document_Date_Number])),0)))>0,Sum([Scenario opening balance]) over (allPrevious([Document_Date_Number])) - (If(sum([Rolling_total_cash_calculated]) over (allPrevious([Document_Date_Number]))>0,Sum([Monthly_impact_on_cash_calculated]) OVER (allPrevious([Document_Date_Number])),0)),0)
Assumptions--
Data has been pivoted into three columns([Document_Date_Number], Monthly_impact_on_cash_calculated] and [Rolling_total_cash_calculated])
where:
[Scenario opening balance] = 150000000(fixed)
[Document_Date_Number] = Jan,Feb,Mar etc
[Rolling_total_cash_calculated] = Rolling total(excel)
[Monthly_impact_on_cash_calculated] = Monthly impact on cash(excel)
But I get incorrect results for some reason
results in spotfire
But the expected result is
Correct result in excel
So although the results match till Oct as shown above they don't seem to match afterwards.
Please let me know what can I do to get the same values. Any help in deeply appreciated.

Related

Sort data contained in blocks in excel

I have a large amount of reference data in excel, which I am trying to manipulate in a variety of ways. I'm having some problems with the way it is structured and sorting into a more manageable format.
Problem number 1:
I have three columns. Column A contains first a date, and then a designator of high or low. Column B contains times, Column C contains heights.
I would like to sort the data by column B (easy enough) EXCEPT I would like the date headings in Column A preserved. It's almost as though I have 365 tables, each with between 3 and 5 pieces of data - I'm looking to sort the 3 - 5 pieces of data within each date only.
This is what I have currently:
There's no issue with me taking the data and manipulating it some other way first - this is ultimately around me being able to take a batch of data (5x different reference points, each for 365 days) and develop a process to sanitise it and get it displayed in time order, as well as being able to get it into a usable format for problem 2 (I need to adjust some other data points by the sorted data once I have it).
This is what I would like it to look like (I manually went through each of these blocks and sorted them):
It is possible to do it in Excel as follows in cell E2:
=LET(rng, A1:C11, set, FILTER(rng, (INDEX(rng,,1) <>"")),
dates, SCAN("", INDEX(set,,1), LAMBDA(acc, item, IF(ISNUMBER(item), item, acc))),
in, FILTER(HSTACK(dates, set), INDEX(set,,2)<>""), inDates, INDEX(in,,1),
out, REDUCE("", UNIQUE(inDates), LAMBDA(acc, date,
LET(sorted, VSTACK(date, DROP(SORT(FILTER(in, inDates = date),3),,1), {"","",""}),
VSTACK(acc, sorted)
))), IFERROR(DROP(DROP(out,1),-1),"")
)
Here is the output:
You can avoid the clean-up process except for removing the last row as follow:
=LET(rng, A1:C11, set, FILTER(rng, (INDEX(rng,,1) <>"")),
dates, SCAN("", INDEX(set,,1), LAMBDA(acc, item, IF(ISNUMBER(item), item, acc))),
in, FILTER(HSTACK(dates, set), INDEX(set,,2)<>""), inDates, INDEX(in,,1),
out, REDUCE("", UNIQUE(inDates), LAMBDA(acc, date,
LET(sorted, VSTACK(HSTACK(date,"",""), DROP(SORT(FILTER(in, inDates = date),3),,1),
{"","",""}), IF(MAX(LEN(acc))=0, sorted, VSTACK(acc, sorted))
))), DROP(out, -1)
)
Explanation
Basically is to carry out the manual steps but using excel functions. The name set, is the same as the input data (rng) but we removed the empty rows. The name dates, is a column with the same size as rng, repeating all the dates. The condition in the SCAN function to identify a new date is ISNUMBER because dates are stored in Excel as whole numbers. The name in has the data in the format we want for doing the sorting and filter by date removing the date header and adding as the first column the dates.
Now we use DROP/REDUCE/VSTACK pattern (check the answer to the question: how to transform a table in Excel from vertical to horizontal but with different length provided by David Leal) to append each sorted data for a given unique date. We add the date as the first row, then sorted data, and finally an empty row to separate each group of data. Finally, we do a clean-up via IFERROR/DROP to remove the #N/A values and the first and the last empty row.

Excel power query average of all values in a column

I have a table in power query and I want to create a new column that displays the average of all values of another referenced column. Any idea how to achieve this? So for example the home.goaldFor column i want to add-up all values and devide by the number of values.
i have tried multiple ways, including this one:
Avg = List.Average(
Table.SelectColumns(
#"ENG - Premier League",
[home.goalsFor],
0
)
)
But that's giving me the error:
Expression.Error: A cyclic reference was encountered during evaluation.
Anyone any ideas ?
I suspect that #"ENG - Premier League" the name of the current step based on the error you're getting.
Try this instead:
Avg = List.Average(#"Previous Step Name"[home.goalsFor])

Index Match to return MAX Date with multiple criteria

apologies for this, I'm assuming this is simple but a few hours of SO googling hasn't helped
Enough whining from me:
Consider the following dataset:
ID, Date, Review, Review Status
1 01/02/18, "Cool", Positive
1 01/03/18, "Awesome", " Positive
1 01/01/18, "Cumbersome", Negative
1 01/02/18, "Rubbish!", " Negative
I'm currently using an array type index match to get the latest review based on a few conditions
I have two columns one which says positive, one negative.
in each of the column I would like to return the latest positive review but I'm unsure how to get the max date within the below formula:
{=index(C2:C4, MATCH(1,(1 = A2:A4)*("Positive" = D2:D4)*(maxdatehere = B2:B4),0))}
The data I have is around 7k rows and is Google Review Data and pretty much matches the example above.
I'd rather not use VBA as I've never really used it before (but will do so grudgingly)
as this is excel I've not created a google demo sheet, but happy to do so for ease of the experts and for others to benfit if they find there way here one day.
If you have Office 365:
=INDEX(C2:C5, MATCH(1,(1 = A2:A5)*("Positive" = D2:D5)*(MAXIFS(B:B,A:A,1,D:D,"Positive") = B2:B5),0))
Confirme with Ctrl-Shift-enter instead of Enter when exiting edit mode.
If you have 2010 or later then:
=INDEX(C:C,AGGREGATE(15,7,ROW(C2:C5)/((A2:A5=1)*(D2:D5="Positive")*(AGGREGATE(14,7,B2:B5/((A2:A5=1)*(D2:D5="Positive")),1)=B2:B5)),1))
Entered normally.

sum two values of dimension but show the result only in one of them in PowerPivot / DAX

It might be a easy one but I cannot solve it so please advice.
I would like to add up two months in a measure (like the current and the previous one) but when I represent the figure in a pivot table I want to show the result only in a current month.
Here is the formula I tried:
CALCULATE([Revenue],FILTER(Tbl_Period,Tbl_Period[Month_nr] = 3)) +CALCULATE([Revenue],FILTER(Tbl_Period,Tbl_Period[Month_nr] = 4))
But logically when I represent it in pivot table the revenue is appear under the two months:
See the picture of the result of the below formula:
What I want to achieve instead is the following:
See the picture of the aimed situation:
I already managed to solve with the ALL function to show the value in all the months but not only for July as I wanted. Here is the formula for that one:
Revenue:
=CALCULATE([Revenue],FILTER(ALL(Tbl_Period[Month_nr],Tbl_Period[Period_id]),Tbl_Period[Month_nr] = 3)) +CALCULATE([Revenue],FILTER(ALL(Tbl_Period[Month_nr],Tbl_Period[Period_id]),Tbl_Period[Month_nr] = 4))
Thanks in advance for the help!
I'm a little bit blind, since you haven't mentioned the structure of your Tbl_Period table.
There are many helpful functions built into dax that can save you a lot of work if you have a date table. One that would be relevant here is PREVIOUSMONTH().
Working with just the information you have provided, you can get a measure to show the previous month's revenue like this:
LastMonthRevenue: = CALCULATE([Revenue], FILTER(ALL(Tbl_Period), Tbl_Period[Month_Nr] = MAX(Tbl_Period[Month_Nr]) - 1))
and then
TwoMonthsRevenue: = [Revenue] + [LastMonthRevenue]

DAX Count function making mistake somewhere

File: count.xlsx located on GitHub repository
Software: MS Excel 2016 Power Pivot
I know for fact there are 10,921 rows in EXCEL sheet.
When I create DAX measure Total_Incidents:=Count(Graffiti[CREATED_DATE]) value comes to 10,921. I count the CREATED_DATE because there is no NULL value.
There are three statuses, Open, Pending, Closed which are calculated as follows
Total_Closed:=sumx(FILTER(Graffiti,Graffiti[STATUS]="Closed"),[Total_Incidents])
Total_Closed= 5354, <- correct
However, Total_Opened is incorrect
Total_Opened:=sumx(FILTER(Graffiti,Graffiti[STATUS]="Open"),[Total_Incidents])
Total_Opened= 4483 it is supposed to be 4481
However Total_Pending is correct
Total_Pending:=sumx(FILTER(Graffiti,Graffiti[STATUS]="Pending"),[Total_Incidents])
Total_Pending= 75, <- correct
When I add totals I get 2 more incidents because of Total_Opened
Total_Calc:=[Total_Closed]+[Total_Opened]+[Total_Pending]
Total_Calc= 10923 <- incorrect, should be 10921
Why the discrepancy in Total_Opened? Cannot figure this.
I had originally answered with this:
"I know you said you count CREATED_DATE because there is no NULL value, but did you check for blanks in your CREATE_DATE column? I duplicated your problem by having blank dates. You could have 2 blank dates.
You could use COUNTBLANK(Graffiti[CREATED_DATE]) to check if you do have blanks."
Then I noticed you had a link to your Excel file on GitHub, so...
I downloaded it and I looked for blanks in your dates--there were none.
So I added columns for Total_Closed, Total_Opened, Total_Pending and Total_Calc. (I used your formulas, but instead of sumx, I used countx in each formula, so I could just compare row counts.)
Total_Incidents:=Count(Graffiti[CREATED_DATE])
Total_Closed:=countx(FILTER(Graffiti,Graffiti[STATUS]="Closed"),[Total_Incidents])
Total_Opened:=countx(FILTER(Graffiti,Graffiti[STATUS]="Open"),[Total_Incidents])
Total_Pending:=countx(FILTER(Graffiti,Graffiti[STATUS]="Pending"),[Total_Incidents])
Total_Calc:=[Total_Closed]+[Total_Opened]+[Total_Pending]
Here's what I got:
Total_Incidents: 10921
Total_Closed: 6365
Total_Opened: 4481
Total_Pending: 75
Total_Calc: 10921
These counts look correct.
I'm guessing you figured out and corrected your problem.

Resources