Forum Discussion
Assigned to Previous column
The below table has two columns.
| Event | Target |
| C | 0 |
| C | 0 |
| C | 3 |
| R | 0 |
| R | 0 |
| R | 0 |
| C | 0 |
| C | 2 |
| R | 0 |
| R | 0 |
My requirement is Target Column.
Target:
The count of R values will be assigned to the previous Cell or Record of the first R.
In this example, R will start from the 4th cell up to the 6th cell. The total Count is 3.
The value 3 will assign to the 3rd cell ( before the cell where the first R appears)
Same as the 9th and 10th having R, the count is 2. That has been assigned to the 8th cell.
I hope you understand the requirement.
10 Replies
- sivasrao
Helper III
Thank you for your quick reply.
It is from my source data. These 2 columns are important in my table to satisfy this requirement.
Need the count of R values and should appear before the row or cell where the first R appears only.
The remaining R values and C values are 0.
- johnyip
Solution Sage
Do you have some columns like [ID] in your data, so your data (table) is always displayed like the way you show? And from your requirement, for this moment I believe preparing your data in Excel and then load it in PowerBI is the easiest way.
- sivasrao
Helper III
- johnyip
Solution Sage
sivasrao , I cannot quite figure out the PowerBI way right now, but I can figure that out using Excel formula.
The following are the data I mimicked using MS Excel.
The forumlas are as below:
A B =AND(A2="R",A3="R") C =IF(AND(A2="R",A3<>"R"),TRUE,FALSE) D =IF(OR(B2=TRUE,C2=TRUE),1,0) E =IF(AND(B2=FALSE,C2=FALSE,OR(AND(B3=TRUE,C3=FALSE),AND(B3=FALSE,C3=TRUE))),SUM(D2:INDIRECT("D"&MATCH(TRUE,C2:C$1048576,0)+ROW(D2)-1)),0) Just prepare your column A in Excel format, with the headers in row 1. Paste the formulas in B1 to E1 and then drag then down to your end of the data.
Finally, load column A and column E in the PowerBI.
- sivasrao
Helper III
Thank you for the reply.
I will go through it.