PowerBI recursion calculation using Dax or Power query - Each row column value needs to refer previous row same column value - powerbi

I have requirement where I have to apply formula which refers itself (recursive). Each column needs to be refer to previous row column value.
Please find attached excel sheet for formula reference. I need to calculate calc_amt field.
Please check formula used. Field refers itself for index 1 onwards for each uid.
For each uid, eff_date repeats.
Any help here would be great
https://i.stack.imgur.com/aBaae.jpg[enter image description here]1
Ron, sorry I was out of town and sorry for the delayed response.
I wanted to attach the excel sheet with formula but looks excel attachment is not allowed. I have attached the image again taken from excel. Column K has the formula. For index 1 and above, column refers itself. This repeats for each uid.

Related

How do I create an Other category in PowerBI Desktop?

I am learning Power BI Desktop. I have a project already loaded for which I have created a
pie chart.
As you can see, the data is currently divided into two years: 2022 and 2021.
I also have data for previous years that I want to include in the chart. Unfortunately, none of these years has a high number. So I want to group them all into an "Other" category.
I've already tried using the RANKX function as described here (where I copied and pasted the formula from the comment and replaced the field name with my own) and here (where I went through the article step by step using my own field names). I used the exact format shown in both the comment and the article:
Rank = RANKX('Table','Table'[Percent],,DESC,Dense)
(Table is the table name I am using and Percent is the column I am trying to rank.)
When I added the new column to a table, though, PowerBI automatically gave me a sum calculation. This calculation gave me a 1 in each column. When I asked it not to give me a sum, it said it could not display the visual and took me back to the calculation screen.
EDIT: Thanks for your help Kevin! This is the table I tried to draw from. I am an idiot sometimes.
EDIT 2: Now I am trying to use a different field in the formula:
Rank = RANKX('FactClaimActivity','FactClaimActivity'[DirectIncurredLoss_ITD])
(This is the original field that I tried to base Percent on)
My table looks like this. (Yes, I know that 2016, 2017, 2019 and 2020 have negative values and 2014 and 2015 have $0 values. I just want to show what the data is.)
EDIT 3: This time I am also getting an error when I type in the formula, which says "A single value for column 'DirectIncurredLoss_ITD' in table 'FactClaimActivity' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result."
I do not understand why it wants a single result for a formula that ranks the data points based on this field. That seems like it defeats the whole purpose of the formula.
Yet when I use the formula, I get the same result as last time! This column is in the Fixed decimal number format, and it does have many different values.
EDIT: I've found the answer
New Category = IF('FactClaimActivity'[Rank]<=2,'FactClaimActivity'[LossYear],"Other")
The formula will help you get the correct result.

If statement based on presence of duplicates

If the data in column A is found in multiple rows, look at the data in column C for those duplicate rows. Whichever is highest value in C, return the value from the respective row but column B. In my picture, I'm trying to populate the stuff in yellow automatically, ideally with formulas in excel. Any help is greatly appreciated.
enter image description here
My first attempt was this (a formula that you may copy on cell D2):
=INDEX($A$2:$C$9,MATCH(MAX(IF($A$2:$A$9=A2,$C$2:$C$9)),$C$2:$C$9,0),2)
This is what it does: the combo INDEX-MATCH does what VLOOKUP does, but it is more efficient than VLOOKUP. Basically it commands Excel to navigate the $A$2:$C$9 range and then find the following match:
Find the row with the MAX price for the same Item (this part: MAX(IF($A$2:$A$9=A2,$C$2:$C$9)));
Then return whatever value is on column B, at that row.
Albeit this formula seemed to work, I tried something out: what if, by some unfortunate coincidence, the MAX price for two items was the same?
This is what happens when CDE888 sells for 217
Thus, one can tell the formula above is wrong and needs a fix. This is the new formula:
INDEX($A$2:$C$9,MATCH(A2&MAX(IF($A$2:$A$9=A2,$C$2:$C$9)),$A$2:$A$9&$C$2:$C$9,0),2)
This time, the formula looks for a value that is composed of the Item code AND its highest price.
The rest works exactly as the first formula.
One last word: I wrote this formula on cell D2, then dragged the formula down.

Calculated field Sub total in pivot table is not displaying correct value

I am working on QuickSight in AWS. I am trying to achieve weighted average value in a Pivot table.
I am using SPICE data to create this analysis.
I have created a calculate field (WAM) in analysis with formula "percentOfTotal(sum(upb),[{pool_num}]) * sum({remaining_terms})".
This gives me the desired value on each row level, but the sub total of a particular column is not reflecting the total of values in the calculate field, rather it displays the sum of original values in the "remaining_terms" field.
Please see below image for the same. Can some one please through some light on this ?
Thanks in advance for your help
Please note that I have tried the same in Excel pivot table and it works perfectly.
Try to remove the 2nd argument from the percentOfTotal function. For example, just do:
percentOfTotal(sum(upb))
I am not 100% this will work but one thought it that it would match the remaining_terms value if the percentageOfTotal was 1 (i.e. 100%) and you may not need to provide a partition argument in a pivot table since pivot tables implicitly provide partitions.
I have solved the problem in a different way. See below what I have done.
WAM = percentOfTotal(sum(upb),[{pool_num}]) * sum({remaining_terms}).
It looks like QuickSight treats the subtotal as a row and the above function is applied on the subtotal, hence it is converted as
(1186272.5 / 1186272.5) * 31 = 31.
I have tried to produce the desired result by introducing another custom field with formula
SUM_WAM = sumOver({WAM},[{pool_num}]).
This gives me the output I need, but in a column. See the screen shot attached

Same row different column. Excel Formula

If is possible with the if(indirect formula to give me the value from the same row but from a different column if a specific cell is from that row?
More specific: I want cell =Sheet2!F23 to give me =Sheet1!N11 if =sheet2!C23 is from Sheet1!B11.
The important thing is the I need it to come from row 11 but from a different column.
Thanks in advance.
I did the following:
On Sheet 1 i gave all the rows a unique number in column A
On sheet 2 i just put in the unique number(C23) and the rest of the cells on that row used the formula below with. The only thing i needed to change was the index of which column needed to be matched.
It might not be the most efficient way but i worked for me.
=IFERROR(INDEX(Sheet1!B:B;MATCH($C23;Sheet1!$A:$A;0));"")

Adding more condition to Vlookup

I want to use vlookup formula with 2 scenarios:
Example: I have sheet 1 with full data and Sheet 2 with other information. In sheet 2 I want to pull those records which exists in sheet 1 with vlookup. I have already wrote that query for vlookup. In same I want to add below conditions:
1) column c2,A2 & G2 of sheet2 are matching in any row of Sheet 1.
My vlookup formula is this:
=VLOOKUP(A2,Sheet3!$A$2:$J$20332,10,FALSE)
There are duplicate rows in column A and thats why it is not working as a primary key. Kindly share your thought.
You should be able to construct a primary key by linking together all the information which will create a singular entry.
Given the limited info you provided I would go with creating in both sheets a new column with:
=A2&C2&G2
You could then do a vlookup based on this singular value and get the information from one sheet into the other.