Error 'The expression refers to multiple columns - powerbi

Does anyone know why this measure is throwing up an error 'The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.
MALS Lastweek =
CALCULATE (
COUNT ( vw_sana_account[new_mal] ) = 1
&& FILTER ( DateTable, DateTable[LastWeek] = "Yes" )
)

Yep, your syntax is wrong. This is what you are looking for:
MALS Lastweek = Calculate(Count(vw_sana_account[new_mal]), DateTable[LastWeek]="Yes")
You dont need Count() = 1. It does automatically add 1 in the count function and if you use Calculate() your second argument is the filter.
This measure needs a relationship between the vw_sana_account and the DateTable tables by the way.

Related

How do you exclude negative values in an iterator function?

I am putting together a measure of the difference between two datetime values and have ran into negative durations due to bad data, that I need to omit from the calculation.
My DAX function is as follows:
Job_length =
SUMX (
jobs ,
DATEDIFF (
jobs[actualstart] ,
jobs[actualend] ,
MINUTE
)
)
This returns the following output:
How can I change the formula to skip rows where the iterator expression returns a negative value?
The question is a bit lacklustre in the sense that it is perhaps the wrong question that is being asked! E.g. why is there data where actualstart < actualend to begin with? This is something you should fix in ETL prior to loading data into Power BI.
Or better yet, ensure that this is not allowed within your source systems. Perhaps there is a bad setting somewhere in your stack that results in this behavior in the data.
However, to do exactly as you describe you can apply a filter to the table you are iterating over within the SUMX function to remove rows that don't comply with the requirement. I have here assumed that only rows where actualend is strictly greater than actualstart are evaluated:
Job_length =
SUMX(
FILTER (
jobs ,
[actualstart] < [actualend]
),
DATEDIFF (
jobs[actualstart],
jobs[actualend],
MINUTE
)
)

How can I calculate how many times a value is present excluding another value?

I have a column for which I need to count how many times the value "Good" is present without calculating the "Neutral" Value?
This is the sample table:
Col1
Bad
Neutral
Good
Bad
Neutral
Okay
Here is what I have so far but I kept
Measure = CALCULATE(Col1],Table[Col1] = "Good",ALLEXCEPT(Table,Table[Col1]="Neutral" ))
but I end up getting this error:
A single value for column 'Intune Owner Email' in table 'users' 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.
How can I work around this?
Why whould you need to except Col1 = Neutral for this?
This measure counts the number of rows where Col1 = "Good":
# Good :=
CALCULATE (
COUNT ( 'Table'[Col1] ) ,
'Table'[Col1] = "Good"
)
If you are after a different type of filtering semantics, you can try also invoking KEEPFILTERS:
# Good Variant =
CALCULATE (
COUNT ( 'Table'[Col1] ) ,
KEEPFILTERS ( 'Table'[Col1] = "Good" )
)
The difference between the semantics can be shown here:

Power BI - Getting the most recent value from a related table

I know this must be extremely simple, but every example I can find online only works within a single table. I've simplified my situation to these two tables:
I want to add a calculated column to the first table, showing the most recent value for that id. It also needs to work with text.
There are a variety of ways to do this kind of thing as I've explained before and all of the solutions there can be adjusted to work in this case.
Doing this as a calculated column and with a second table, you need to make sure you are using row context and filter context appropriately.
Here's are a couple different possibilities I think may work:
MostRecentValue =
MAXX ( TOPN ( 1, RELATEDTABLE ( Table2 ), Table2[date] ), Table2[value] )
In this one, RELATEDTABLE is doing the work of filtering Table2 to only the rows where id matches Table1.
MostRecentValue =
VAR PrevDate = CALCULATE ( MAX ( Table2[date] ) )
RETURN CALCULATE ( MAX ( Table2[value] ), Table2[date] = PrevDate )
The relationship is more subtle here. Wrapping the MAX in CALCULATE forces a context transition so that the row context (which includes id) is applied to Table2 as filter context.

Calculated column or measure using IF statement

Objective:
I would like to make a measure and a calculated column (for the sake of knowing how to write both) using an IF statement but can't get it to work
Query:
Column =
IF(
Refund[orderTotalPrice]=Refund[amount] && Refund[status] = 'refund' ,
Refund[amount] - Refund[total_tax]- Refund[shipping_price],
Refund[amount]
)
the expression refers to multiple columns multiple columns cannot be converted to a scalar value
When creating an if statement in a calculated column you can only have one comparison statement. If you want 2, like in your example, you need to use the AND function. Also make sure you use " instead of ' for string comparison.
I tested this calculated column and this worked for me:
Column = if(
AND(Refund[orderPriceTotal]=Refund[amount],Refund[status]="Refund"),
Refund[amount] - Refund[total_tax] - Refund[shipping price],
Refund[amount]
)
In your case, I do not think there is an easy solution to solve this in a measure. Why would you want to build it as a measure?

DAX A table of multiple values was supplied where a single value was expected

I am trying to return the respective rating that a particular value in a column falls within. For example, if the grade is 90< and >100 assign A. However, the formula I am using is resulting in the error. "A table of multiple values was supplied where a single value was expected."
Availability Rating =
CALCULATE (
VALUES ( 'Rating Matrix'[Rating] ),
FILTER (
'Rating Matrix',
'Rating Matrix'[Avaibility (L)] <= 'Equipment_Status'[Availability]
&& 'Rating Matrix'[Availability (H)] >= 'Equipment_Status'[Availability]
&& 'Rating Matrix'[Bus Type] = 'Equipment_Status'[Helper]
)
)
This is the helper field referenced in the formula which distinguishes 2 types of assets.
Helper = RELATED('Performance Matrix'[Helper])
This error message is usually related to the VALUES function. Since this function can return multiple values (all the existing values in the local filter context) but measures can only output a single value, you get an error in the cases where it does return more than one value.
In the case where there are multiple values, you need to decide which one you want to pick or how to aggregate them. You could take a MAX or MIN, SUM or AVERAGE, or you could even CONCATENATEX them all into a single string.