I am trying to do this expression but this shows an error:
vMotor_Paid =
CALCULATE (
Paid_excel,
SUM ( Paid_excel[PAID_AMOUNT] ),
Paid_excel[Flag] = "Paid",
Premium_Excel[LOB] = "MOTOR",
Paid_excel[PAID_DATE] = { [VpeDate] }
)
Error:
A function 'SUM' has been used in a True/False expression that is used as a table filter expression. This is not allowed.
In the expression, I am trying to do SUM of paid_amount against filters of these
Paid_excel[Flag]="Paid",
Premium_Excel[LOB]="MOTOR",
Paid_excel[PAID_DATE]={[VpeDate]}
Here I create another variable of VPeDate where I fixed the date "23-12-2017"
Any help?
I don't understand why your date is wrapped in curly braces. I think you might have more luck like this:
vMotor_Paid =
VAR VpeDate = [VpeDate]
RETURN
CALCULATE (
SUM ( Paid_excel[PAID_AMOUNT] ),
Paid_excel[Flag] = "Paid",
Premium_Excel[LOB] = "MOTOR",
Paid_excel[PAID_DATE] = VpeDate
)
Now that CALCULATE filter is comparing versus a date rather than an expression that returns a date.
vMotor_Paid = CALCULATE(SUM(Paid_excel[PAID_AMOUNT]),FILTER(Paid_excel[Flag]="Paid"
,Premium_Excel[LOB]="MOTOR",Paid_excel[PAID_DATE]={[VpeDate]}))
Please check the calculate syntax
Related
While executing the below DAX expression, I am getting an error "USERELATIONSHIP function can only use the two columns reference participation in relationship".
So could you please help me with that what's wrong with the expression?
Accuracy_Last_6_Month =
VAR ReferenceDate = MAX(Calender[Date])
VAR Last_6Month =
DATESINPERIOD(
Calendar_Last6Month[Date].[Date],
ReferenceDate,
-6,
MONTH
)
VAR Result =
CALCULATE(
[Accuracy],
REMOVEFILTERS(Calender[Date]),
KEEPFILTERS(Last_6Month),
USERELATIONSHIP(Calender[Date],Calendar_Last6Month[Date].[Date])
)
RETURN
Result
Relationship created between tables as inactivated form:
Columns used in both the table:
You should be able to use a single Calendar. Your second calendar is redundant.
I would write something like this:
Accuracy_Last_6_Month =
CALCULATE([Accuracy],
FILTER(ALL(Calender),
Calender[Date] > MAX(Calender[Date])-180 &&
Calender[Date] <= MAX(Calender[Date])))
I'm guessing the error is because you are using Calendar_Last6Month[Date].[Date] inside USERELATIONSHIP, which isn't actually a table column. Try deleting that .[Date] suffix everywhere in your measure:
Accuracy_Last_6_Month =
VAR ReferenceDate = MAX ( Calender[Date] )
VAR Last_6Month =
DATESINPERIOD ( Calendar_Last6Month[Date], ReferenceDate, -6, MONTH )
VAR Result =
CALCULATE (
[Accuracy],
REMOVEFILTERS ( Calender[Date] ),
KEEPFILTERS ( Last_6Month ),
USERELATIONSHIP ( Calender[Date], Calendar_Last6Month[Date] )
)
RETURN
Result
I generally avoid using these Time Intelligence suffixes entirely.
How to convert the following DAX expression to a scalar?
SELECTCOLUMNS(FILTER(rules, rules[RuleNumber] = 1), "AntecedentID", [AntecedentID])
This returns a table with a single cell, but I need a scalar value.
Tried wrapping the expression into a VALUES or a MAX, but no luck.
M =
CONCATENATEX (
SELECTCOLUMNS (
FILTER ( rules, rules[RuleNumber] = 1 ),
"#AntecedentID", [AntecedentID]
),
[#AntecedentID],
", "
)
I have several dataset tables in PowerBI report. The column country comes from TABLE1 while the column name comes from TABLE2.
So firstly I want to calculate min_number based on country and name, and then if min_number = number, the min will be 1; otherwise, 0. So the result table looks like:
This is my code for min
min =
VAR min_number =
CALCULATE (
MIN ( [number] ),
ALLEXCEPT ( TABLE1, TABLE1[country] ), ALLEXCEPT (TABLE2, TABLE2[name])
)
RETURN
IF ( [number] = Min_number,1, 0 )
I got an error: the MIN function only accepts a column reference as the argument number 1. Does it mean if it has to be one condition? how to fix it? Thank you
I would solve it by just making two separate measures, since we want to see the both results in the final table anyway.
First the min_number calculation:
min_number = CALCULATE(MIN('Table'[number]);ALLEXCEPT('Table';'Table'[country];'Table'[name]))
And the min measure:
min = IF(MAX('Table'[number]) = [min_number];1;0)
As we are using a measure, we can use MAX, so it will know what number to reference in the IF. It will still use the MAX number per row, so results are correct.
You can try with this below measure-
min =
VAR current_row_country = MIN(table1[country])
VAR current_row_name = MIN(table1[name])
VAR current_row_number = MIN(table1[number])
VAR min_number =
CALCULATE (
MIN (table1[number]),
FILTER(
ALL(table1),
table1[country] = current_row_country
&& table1[name] = current_row_name
)
)
RETURN IF (min_number = current_row_number,1, 0 )
Problem: DAX is not returning expected result in if statement with operator when date is a variable.
Background: I've checked to make sure that there is no date or time difference.
Dates are ALL in format (1stday of month, 12:00:00AM). I have 2 years (2018 & 2019: 24 distinct dates).
I've tried to use the <= operator in a calculated column to determine if a date is "Before/Same" to a variable date or "After". I've tried to combine < filter and = filter with || (or), same result.
TestColumn =
var CurrentDate = [Current_Period]
return
IF(
ValuesTable[Month-Year] <= CurrentDate,
"Before/Same", "After"
)
FYI: The [Current_Period] Measure, this works fine, returns one date as expected
Current_Period =
VAR ThisActMonth =
CALCULATE (
DISTINCT ( Fact_FX[Month-Year] ),
Fact_FX[bool_Latest_FX_Act] = TRUE ()
)
RETURN
ThisActMonth
I would expect that for every row where the Month-Year (Date) <= the result would be "Before/Same";
however, The result I currently get is:
"Before/Same" only where ValuesTable[Month-Year] = CurrentDate
CurrentDate = April 2019
"After" all other Months (23)
Please Help!
What's happening is that you are evaluating your Current_Period measure within the row context of the calculated column, so the measure doesn't see the row with Fact_FX[bool_Latest_FX_Act] = TRUE () except in the April row.
The solution is to calculate the Current_Period outside of that evaluation context and there are multiple possible approaches. A quick solution would be to remove row context using the ALL function inside of your CALCULATE:
Current_Period =
VAR ThisActMonth =
CALCULATE (
DISTINCT ( Fact_FX[Month-Year] ),
ALL( Fact_FX ),
Fact_FX[bool_Latest_FX_Act] = TRUE ()
)
RETURN
ThisActMonth
Is it possible to use a variable within a DAX measure expression?
For example, the following measure isn't working (it always returns 0).
Notice the second variable below is referencing the first:
Measure =
VAR ThisMonth =
CALCULATE (
ABS ( SUM ( 'Table'[Saldo] ) );
FILTER ( Table; Table[Conta] = 71 )
)
VAR PreviouzMonth =
CALCULATE (
ThisMonth;
PREVIOUSMONTH ( 'Calendário'[Date] );
FILTER ( ALL ( 'Calendário'[Mês] ); MAX ( 'Calendário'[Mês] ) > 1 )
)
RETURN
ThisMonth-PreviouzMonth
But if the two variables above are calculated separetely - ie as two different measures - the calculation works fine.
Thanks for supporting!
You can have variables in expressions.
The issue is somewhere else.
Something simple like this work;
Measure =
VAR X = SUM('Sheet1 (3)'[Total])
VAR Y = DIVIDE(X,5,0)
RETURN X-Y
When you use ThisMonth inside calculate, it's not an expression. It's a variable. That might be it.