In SSAS, I wanted to create a measure that counts the number of rows which the column values contains a specific string.
eg. table
|Id|item
|1|greenapple
|2|blueapple2
|3|yellowapple
|4|purplegrape
search for "apple".
i want the measure return 3.
how should i write the DAX expression?
thanks.
Step 1 first add a column in your table
AppleFlag := if(SEARCH("apple",Table1[Name],1,0)>0,1,0)
Step 2 then create Measure
Apple Count := SUM(Table1[AppleFlag])
Related
On my table (point1) I am trying to get, that for each table of the grouped rows (point 2) I will have new row inserted (point 3) at the beginning of each table with the value in the column "Metadata1" equal to value form "Column2" for original row number 2 (starting counting from 0).
Link to excel file:
https://filebin.net/cnb4pia0vvkg937g
Its hard to know how much of your requirement is generic or specific, but
TransformFirst = Table.TransformColumns(#"PriorStepName",{{"Count", each
#table(
{"Column1","Column2","Metadata1"},
{{_{0}[Column1],_{0}[Column2],_{2}[Column2]}}
) & _
}}),
Together=Table.Combine(TransformFirst[Count])
in Together
modifies all the tables in column Count to include an extra row that is made up up Row0/Col1 Row0/Col2 and Row2/Col2
It then combines all those tables into one table
I want to count the number of rows since the last occurrence of a specific value, while excluding rows where the cell is a blank or empty value. I have provided a sample of fake data to try to explain what I'm asking. So, with the sample data, on every occurrence of "Apple", I would like to show the number of valued rows since the last occurrence of "Apple". I currently have a formula like this:
=ROW()-MAX(FILTER(ROW(INDIRECT("B1:B"&ROW()-1)),INDIRECT("B1:B"&ROW()-1)=INDIRECT("B"&ROW())))
The formula gives me the number of rows since the last occurrence, but does not exclude the blank cells, and I'm wanting to figure out a way to get this result without counting the rows with blank cells in the column.
Sample Data
Assuming values are in range A2:A and we want the results in column B, use this formula in cell B2 and then manually extend down:
=IF(A2="Apple",IFERROR(MATCH("Apple",QUERY({A$2:A2,SEQUENCE(ROWS(A$2:A2))},"select Col1 where Col1 is not null order by Col2 desc offset 1"),0),0),)
Explanation
The QUERY retrieves all values above the current one (e.g. for row 7 it will be A2:A6) in reverse order (A6, A5, ..., A2) and excluding blanks.
MATCH returns the position of the first occurrence of the value in interest in the result of the QUERY.
I was not able easily to make this formula auto-extend using ARRAYFORMULA or MAP(LAMBDA), so it has to be manually extended.
I want to create a row, or some kind of definition, between Google Sheets rows whenever one of the value in my columns contain a new / different value.
Here's an example of the kind of spreadsheets I'm putting together, which shows how Agencies are listed in Column A, and Sub-Agencies are listed in Column B.
I'd like to create some kind of row space / spacial definition between every new / different Sub-Agency, which are values that I enter in Column B of my spreadsheet -- but no space between rows with the same Sub-Agency value. Here's an example of the kind of row space / spacial definition that I'm seeking.
Any ideas / suggestion on how do this?
Many thanks for your help!
You can insert a row after X condition.
Using insertRowAfter(afterPosition) inserts a row after the row you want:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// This inserts a row after the first row position
sheet.insertRowAfter(1);
I have a requirement related as below
1-If there is employee record then count the number of rows
a-if there are four rows then follow the layout 1,
and populate the column1 and column 2 with values in report and ltrimrtrim
b- if there are three rows, then follow the layout 2,
and hardcode the column 1 and column 2 with NULL
Otherwise, look for the employee record.
Couldn't get the logic, I used the router with as if column 1 and two null the send to layout two else 1. But the requirement is different.
router transformation, if null, layout one else 2
Step 1 - Use SRT>AGG>JNR to calculate count. create new column as count_all and set to COUNT(*). Please group by proper key columns.
Step 2 - Use RTR next to split data based on your condition.
group 1- count_all =4 then follow the layout 1 and...
group 2- count_all =3 then follow the layout 2 and...
group 3 - if count <3 then do employee record.
I have a scenario where I need to filter out those records in which few NUMBER columns have zero as its value.
Say record 1 contains: c1_amount= 5, c2_amount=-2, c3_amount=-3 and other columns are having zeroes.
Here, the following code fails, as it will filter out the records which is not exactly what I want because 3 columns has non zero values but after sum resulting zero.
Select * from table where
( C1_amount+
C2_amount+
.
.
.
C50_amount) <>0;
I am little concerned about performance. That is the reason why I neither want to use abs() on all 50 column nor check every column <> 0.
Try to select like
SELECT * FROM Table WHERE
decode(c1_amount,0,0,1)+decode(c2_amount,0,0,1)+..
..+decode(c50_amount,0,0,1)>0
or use ALL
SELECT * FROM Table WHERE
0!=ANY(c1_amount,...,c50_amount)