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?
Related
I have a table like this:
I would like to calculate the result but some of ID column has different calculation formula.
For ID less or equal to 1733 using this formula: Value/3*100 for ID greater than 1733 using this formula Value*100
I tried this way:
Result =
IF('Data'[ID]<=1733,[Value]/23*100)
IF('Data'[ID]>1733,[Value]*100)
But it return an empty value. Anyone could help me please.
Thank you so much
This can be achieved using IF statement by following way by creating a calculated column called "Result"
Result = IF(Data[ID]<="1733",(Data[VALUE]/23)*100,Data[VALUE]*100)
Hope this helps !!
If the [ID] is a text then you can convert it to a number with the VALUE(). When you are trying to convert number to text with quotes then you will get a wrong result for some of values. For text comparison it works like this: "11111"<"2", for number 11111 > 2. For a calculated column it not necessary to write a full column name like 'Data'[ID], you can simply write [ID], because of a row context. DAX will understand that the value and row you are working with is in a current table.
Result =
SWITCH(
TRUE()
,VALUE([ID])<=1733,[VALUE]/23*100
,[VALUE]*100
)
While I am trying to create a new measure, with condition, I am facing the below error.
I am trying to create a dynamic line based on dates on my line graph. For my case, if Sheet[Date] matches to Test[Date] it should return me a value of 100.
But the error says that a single value for column 'Date' in table Sheet1 cannot be determined.
I also tried to convert the date to week with Weeknum function. But the error still persists.
Does it mean that I can not compare single values in IF condition
If there is a way to compare the dates, kindly guide me.
Sheet[Date] and Test[Date] are columns, not single values.
You need to specify which single values from those columns to compare. For example, you could compare the maximal values of those columns (within the local filter context):
MAX ( Sheet[Date] ) = MAX ( Sheet[Date] )
I am facing an issue while working with power bi desktop. i am having an csv file as a datasource and i am having a column with multiple values, say "abc, def", "jkl" "zyz" etc.
Here, i need to generate a report with rows having showing "def" & "jkl" .
How to filter this using DAX Filter command. i wanted to fetch, filter only two values CTF& EVE in the Power BI report.
I tried with creating a calculated column and applied the below code but it didnt work:
Columnjkl = FILTER((Table1,OR(Table1[mycolumn1] == "def" || "jkl"))
filter-2cols-ctf-eve-
You need to read how DAX syntax is written, check this page to see how you use the FILTER function (FILTER) and this for how to use the OR function (OR)
Basically, Filter returns a table, so using it to calculate a column will not work. However, by implementing the FILTER function inside a CALCULATE you can change/modify what the main argument of CALCULATE will evaluate. The calculation flow in DAX is such that first the filter argument is evaluated and then the aggregation (or what ever) is evaluated. Example:
NumberOfRowsWithABC =
CALCULATE =
COUNTROWS('Table1'),
FILTER(
'Table1',
'table1[mycolumn1] = "abc"
)
)
First the FILTER function only selects the rows in 'Table1' where [mycolumn1] has the text value abc. Then it passes this reduced table to the COUNTROW function, which counts the number of rows in the table passed to it.
The syntax for the OR function is wrong. This is how you should write it:
OR(
'Table1'[mycolumn1] = "def",
'Table1'[mycolumn1] = "jkl"
)
Perhaps a better way of writing this OR function is using the in-command as the filter argument of the calculate function:
NumberOfRowsWith_def_and_jkl =
CALCULATE(
COUNTROWS('Table1'),
'Table1'[mycolumn1] in {"def", "jkl"}
)
But as Gangula wrote, you don't need to filter 'Table1' using the FILTER function, it can all be done visually on the dashboard.
I'm trying to use slicer values as calculated column or something that works like one
I've seen this post
https://community.powerbi.com/t5/Desktop/Slicer-Value-in-Column-Formula/m-p/214892#M95071
but not sure how to proceed with the following case
I have registers from a sort of SCD with ValidStartDate and ValidEndDate
User should be able to set 2 slicers: AnalysisStartDate and AnalysisEndDate
I should be able to count registers based on those two dates, for instance
how many registers have ValidStartDate between AnalysisStartDate and AnalysisEndDate?
how many registers have ValidEndDate between AnalysisStartDate and AnalysisEndDate ?
Anyhelp appreciated
Looks like I managed to get to what i wanted
First you need a "measure" version of the columns you want to use in calculation just using FIRSTDATE() for instance -- I think it's very important to create the measure in the same table
To capture slicer value in a measure using something like:
if it has one value, get the value, otherwise use first value (or whatever you want)
x Analisis Inicio = IF(HASONEVALUE(TD_FECHAS_INICIO[DT_ANALISIS_INICIO]);VALUES(TD_FECHAS_INICIO[DT_ANALISIS_INICIO]);FIRSTDATE(TD_FECHAS_INICIO[DT_ANALISIS_INICIO].[Date]))
Now you can start creating measures which compare both
x SW_ES_ALTA =
IF(
AND([x Inicio Measure] >= [x Analisis Inicio]
; [x Inicio Measure] <= [x Analisis Fin])
;"SI"
;"NO"
)
and even counts of this last measure
x HC_ES_ALTA = COUNTAX(FILTER(ZZ_FLAGS_INMUEBLE;[x SW_ES_ALTA]="SI");ZZ_FLAGS_INMUEBLE[ID_INMUEBLE])
Not the easiest path, and probably you can put several of these measures in a single one, but if it works, it works...
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.