I have a set of data where an account id can have multiple rows of country. I'm looking for an array function that will give me a unique list of accounts with the countries in the second column as csv values e.g. country1,country1,country3.
If I unique the accounts, this query will do it per row but I'm really looking for an array so I don't have to maintain it as the number of rows grows.
=TEXTJOIN(",",1,UNIQUE(QUERY(A:B,"select B where A = '"&D2&"'",0)))
I have a sample sheet here.
try:
=INDEX(REGEXREPLACE(TRIM(SPLIT(FLATTEN(QUERY(QUERY(
IF(A2:A="",,{A2:A&"×", B2:B&","}),
"select max(Col2)
where not Col2 matches '^×|^$'
group by Col2
pivot Col1"),,9^9)), "×")), ",$", ))
Related
I have a table like shown below titled Employees:
Name LOC1 LOC2 LOC3 LOC4
-----------------------------------------
Joe DAY CVG DTW
Jane PVD STL
John LAX SAN SFO ANC
I created a measure to combine the LOC fields into 1 result separated by a space. I keep getting errors because PBi wants to aggregate the data fields. All fields are type Text. I've tried all the usual combine methods, below are a couple of examples...
CombineLOCs=CONCATENATE('Employees'[LOC1],'Employees'[LOC2])
CombineLOCs= 'Employees'[LOC1] & " " & 'Employees"[LOC2]
This is what I get back:
"A single value for column 'LOC1' in table 'Employees' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation....etc."
I ultimately have a table visual on my canvas and instead of listing out all of the columns on that table, I just want 1 column with all of the combined LOC values for each employee in it.
If you just want a single column where the LOC columns are joined together, then you need to create a new column within the table, rather than a new measure. A measure expects you to aggregate the values. A column will concatenate the text strings on a row by row basis.
If you select the new column option, either on the table tools or the fields sidebar, then use the concatenate formula in your question, that should work.
With the new column, you can then include the employee name and the associated LOC values.
I'm obtaining a list of unique values with this formula:
=ArrayFormula(VLOOKUP(UNIQUE(REGEXEXTRACT(FILTER(A2:A1000,A2:A1000<>""),"\d+"))&"*",REGEXEXTRACT(A2:A1000,"\d+.+$"),1,FALSE))
I did this for 3 different sheets, in each sheet has different values but in some cases these are repeated across the sheets like this:
These are the final list after the formula:
After this I used this formula
=COUNTIF(Sheet3!$A$2:$A$500,A2)+COUNTIF(Sheet4!$A$2:$A$500,A2)+COUNTIF(Sheet5!$A$2:$A$500,A2)
I get this:
Actually it works as I want but is not a dynamic function I would like to have the list of the unique values and the times appearing across the sheets if is possible
Here is the problem with some text in the row that I have with []
Use below QUERY() formula-
=QUERY({Sheet3!A:A;Sheet4!A:A;Sheet5!A:A},"select Col1, Count(Col1)
where Col1 is not null
group by Col1
label Col1 'List of Values', Count(Col1) 'Count'")
I have a two tables are Data and Report.
Data Table:
In Data table contain two columns are item and supplier code. The item column contain text & number and supplier code column contain as a text.
Summary if CHE record in DATA:
if any of the items have CHE records in the data table, get the values if only one CHE record, and if there is more than one CHE record then compare each column (length and Supplier) and if any of the columns has different value then return MIXED otherwise return Actual value
Summary if no CHE record
if only one none CHE record in the data table then returns the actual values but if more than one none CHE records in the data table for that time, compare the values of each column, and if any column value is different then return MIXED otherwise value.
Summary: no record found in DATA table:
Return N/A
Logic
My first priority is “CHE” and second priority is “KKR” in order get the length and supplier from Data table into the Report Table.
Scenario 1;
If two different supplier {“CHE” & “KKR”} for the same item in data table then I would like to get the data (length and supplier) against “CHE” in report table according to the item. (Please refer the item 123 and 5678 in both tables ”Data” and “Report”)
Scenario 2;
If supplier not repeated according to the item and the item contain either any of these supplier {“CHE” or “KKR”} in data table, in these scenario pull the data (length and supplier) against the item in report table based on the availability in data table. (Please refer the item 5555, 6666, 9876 and 2345 in both tables ”Data” and “Report”)
Scenario 3;
If supplier not repeated according to the item and the item contain either any of these supplier {“CHE” or “KKR”} but the length & supplier are different in data table in these scenario return as a text “Mixed” were belongs to (column; either length or supplier or both) in report table according to the item. (Please refer the item 123456 and 567 in both tables ”Data” and “Report”)
Scenario 4;
If two different supplier {“CHE” & “KKR”} for the same item in data table but the length and supplier are variable in data table in this scenario return as a text “Mixed” were belongs to (column; either length or supplier or both) in report table according to the item. (Please refer the item 116 in both tables ”Data” and “Report”)
Scenario 5;
If records not found in date table the return as “NA” in report table according to the item. (Please refer the items in report in table 4444, 12 and 10)
I am looking for calculated column option in order to achieve my result.
Current logic
I created New table for order for supplier priority
I created two helper column for running count and unique count
Finally I am applying the following calculated column in report table
LENGTH = LOOKUPVALUE(
DATA[Length],
DATA[ITEM],REPORT[ITEM],
DATA[UNIQUE_COUNT],1,"NA")
it almost working fine but it will give a wrong result (item 123456 and 567) were my desired is "Mixed" in report table. I highlighted in red and green snapshot for your reference.
My final result look like this
Herewith attached the PowerBi file for your reference https://www.dropbox.com/s/p81uy12tfh1htwu/AUOM1.pbix?dl=0
Can you please advise.
It's not entirely clear what you're trying to do but I think this measure pattern may help you:
IF (
DISTINCTCOUNT ( DATA[SUPPLIER] ) > 1,
"MIXED",
SELECTEDVALUE ( DATA[SUPPLIER], "NA" )
)
For more than one value, you get MIXED. For one value, you get that single value. For no values, you get NA.
I have two tables. First one represents sales values of company by department, product ID and month. Second table contains sales target by department and month. I want to add a column to second table. It should shows sum of values from table 1 with grouping department and month.
For Example:
For 310101 in Februray sum of values is 110. So, the first row of table 2 should be 110.
Can you please help me with this DAX function?
Create a calculated column in both tables which will represent an unique ID (Eg: ID = Table1[Dpt ID] & Table1[Month]) and join the both tables by this ID field to create a relationship between these 2 tables.
Now, select all the columns from Table 2 and also select Value column from Table 1. You should get the sum by department.
I have the following date table:
When I use the MonthYear Past column and want to sort, the sort order is alphabetically instead of chronical. When I want to change to Sort Order in SSAS tabular model, I choose datekey or date but get the following error:
Property value is not valid
Cannot sort MonthYear Past by Date because at least one value in
MonthYear Past has multiple distinct values in Date. For example,
you can sort [City] by [Region] because there is only one region for each city,
but you cannot sort [Region] by [City] because there are multiple cities for each region.
How can I sort this column chronical?
To solve this:
Because Past is linked with multiple values, I created a new calculated column where when it is past the value is 1, else the value is YearMonth. & then sort order on your new calculated column