I have 3 IF statements, each in a separate column...
Column 1 = IF(RELATED(dim_verification_measure5[measure_check_type])="min",IF([measure_value]<RELATED(dim_verification_measure5[measure_target_value_min]),20,10))
Column 2 = IF(RELATED(dim_verification_measure5[measure_check_type])="max",IF([measure_value]>RELATED(dim_verification_measure5[measure_target_value_min]),20,10))
Column 3 = IF(RELATED(dim_verification_measure5[measure_check_type])="between",IF([measure_value]>RELATED(dim_verification_measure5[measure_target_value_min]),IF([measure_value]<RELATED(dim_verification_measure5[measure_target_value_max]),20,10)))
The resulting value in each column is correct.
However, I would like the see all of the values in the same column. Is it possible to nest all of these IF statements?
Yes, but instead of nesting if statements which are difficult to read, we use the following:
SWITCH(TRUE(),
value, result,
value, result,
else)
Alternatively, use COALESCE() on your existing 3 statements.
Related
Is there a function in Power BI that can check whether a list of specified values (numbers) exists in a column?
For example, in the image below, I have a column with some values and another one with 0 and 1s. You can see that some values are marked with 1 and some with 0. In order to do this, I used IF function, but this is just too cumbersome.
I am looking for a formula that can check if the values from a list like {XXXX, XXXX, XXXX, etc} exist in a column and that can easily be edited when I need to add other values.
Thank you and have a good day!
Best,
Denis
You can do that by adding a custom column for example. If we assume your table is named Table and first column is named Value, then add a custom column like this:
Where the list contains all the values of interest. This will give you a boolean column Flag:
If you want an integer column with 0 and 1 values, then change the column to something like this:
= if (List.Contains({"5006", "4905"}, [Value])) then 1 else 0
I have a matrix in Power BI which shows counts by Category and by Country (please see table 1 below for example).
I want to create a measure to 'suppress' any counts in that matrix (by replacing the count with "...") that are lower than 3 IF the value of another column in the same source table = 1. IF the value is not equal to 1, I want to suppress any counts in that same matrix that are lower than 10.
To clarify, countries 1 to 5 have either a value of 1 or 2 for the column on which the suppression depends, and within the table it would look like this:
With this measure in the values field, this would produce a matrix that looks like this:
I have been able to achieve the first part (suppressing counts less than 3) using the following DAX syntax to create the measure:
Less than 3 = IF([COUNT]<3),"...",[FORMCOUNT]
But I have struggled to incorporate the second condition. I imagined it would look something like this:
Less than 3 or 10 = IF('Table'[conditional column] = 1
,(IF(AND([COUNT]>0,[COUNT]<3),"...",[COUNT]))
,(IF(AND([COUNT]>0,[COUNT]<10),"...",[COUNT])))
But that doesn't work. I have tried various variations of this syntax using functions such as FILTER that allow you to specify the column and condition but no luck.
Any pointers would be greatly appreciated, thanks!
This may not be the perfect answer but the below appears to do what is required:
Two measures are required:
Measure1 = SELECTEDVALUE('Dataset'[Suppression category],"NA")
Measure2 = IF('Dataset'[Measure1] = 1,IF([COUNT]<3,"...",[COUNT]),IF([COUNT]<10,"...",[COUNT]))
Unfortunately can't currently explain why or how the first measure works, other than that I think it serves to select/distinguish between suppression categories 1 and 2.
The second measure uses the first measure as a condition in a nested IF statement, such that if the suppression category = 1, suppress the count if it is less than 3, otherwise do not suppress the count. IF the suppression is not 1, then suppress the count if it is less than 10. Otherwise, do not suppress the count.
I have the following query in M:
= Table.Combine({
Table.Distinct(Table.SelectColumns(Tab1,{"item"})),
Table.Distinct(Table.SelectColumns(Tab2,{"Column1"}))
})
Is it possible to get it working without prior changing column names?
I want to get something similar to SQL syntax:
select item from Tab1 union all
select Column1 from Tab2
If you need just one column from each table then you may use this code:
= Table.FromList(List.Distinct(Tab1[item])
& List.Distinct(Tab2[Column1]))
If you use M (like in your example or the append query option) the columns names must be the same otherwise it wont work.
But it works in DAX with the command
=UNION(Table1; Table2)
https://learn.microsoft.com/en-us/dax/union-function-dax
It's not possible in Power Query M. Table.Combine make an union with columns that match. If you want to keep all in the same step you can add the change names step instead of tap2 like you did with Table.SelectColumns.
This comparison of matching names is to union in a correct way.
Hope you can manage in the same step if that's what you want.
I have 2 column; ID CODE, value
Remove duplicates function will remove the examples with the higher value and leave the lower one. Is there any way to remove the lower ones? The result I expected was like this.
I've tried Buffer Table function before but it doesn't work. Seems like Buffer Table just works with date-related data (newest-latest).
You could use SUMMARIZE which can be used similar to a SQL query that takes a MIN value for a column, grouped by some other column.
In the example below, MIN([value]) is taken, given a new column name "MinValue", which is grouped by IDCode. This should return the min value for each IDCode.
NewCalculatedTable =
SUMMARIZE(yourTablename, yourTablename[IDCode], "MinValue", MIN(yourTablename[value]) )
Alternatively, if you want the higher values just replace the MIN function with MAX.
I have some table data in which I'd like to sum all the values in a specific column of all rows where column A contains string A and/or column B contains string B. How can I achieve this?
This works for one criterium:
=SUM(FILTER(G:G,REGEXMATCH(F:F,"stringA")))
I tried this, but it didn't work:
=SUM(FILTER(G:G,OR(ISTEXT(REGEXMATCH(F:F,"stringA")),ISTEXT(REGEXMATCH(C:C,"stringB")))))
Please try:
=SUM(FILTER(G:G,REGEXMATCH(F:F,"stringA")+REGEXMATCH(C:C,"stringB")))
+ works for or logic. ISTEXT is not needed because REGEXMATCH gives true or false.
OR does not work because filter is an arrayformula, use + in array formulas.
=SUM(FILTER(G:G,REGEXMATCH(F:F&C:C,"stringA|stringB")))
OR is denoted by |
EDIT Added &C:C to denote different Columns