Multiple values in bracket power bi - expression

I have this expression
vOther_OS =
CALCULATE (
SUM ( OS_excel[OS_AMOUNT] ),
Claims_excel[COVER_NAME]={"abc", "def"},Premium_Excel[LOB]="Caar"
)
when i try above expression this shows an error
"A table of multiple values was supplied where a single value was expected"
so this message clearly shows there should 1 value in bracket where i want more than 1 value
as i do this in qliksense expression
sum({<COVER_NAME -= {"abc", "def"},LOB = {'Caar'}>}OS_AMOUNT)

Change your formula to:
vOther_OS =
CALCULATE (
SUM ( OS_excel[OS_AMOUNT] ),
Claims_excel[COVER_NAME] IN { "abc", "def" },
Premium_Excel[LOB] = "Caar"
)

Related

DAX DIVIDE and / operator not returning the same result

We have a report connected, via a live connection, to an analysis services tabular model.
We have this measure:
MeasureX=
VAR NumLogins =
CALCULATE (
[Measure Dynamic Agg],
'Time Periods'[PeriodCalc] = "Current MtD",
'Calendar'[Is Current Month] = "TRUE",
'Measures - Financial Agg'[Formula] = "Num Logins",
ALL ( 'Measures - Financial'[Formula] )
)
VAR NumCategories =
CALCULATE (
[Measure Dynamic],
'Time Periods'[PeriodCalc] = "Current MtD",
'Calendar'[Is Current Month] = "TRUE",
'Measures - Financial'[Formula] = "Num Categories",
ALL ( 'Measures - Financial Agg'[Formula] )
)
RETURN
DIVIDE(NumLogins ,NumCategories)
In the dashboard this returns blanks everywhere.
If we change the last line of DAX to the following it returns numbers as expected:
...
...
RETURN
NumLogins / NumCategories
Does anyone have any clue what is happening? I was under the impression that semantically using the / operator and DIVIDE function were the same, apart from handling divide by zero differently?
DIVIDE handles both zeroes and blanks in the denominator. It's the blanks that are getting you here. Check out https://learn.microsoft.com/en-us/dax/best-practices/dax-divide-function-operator.

Issue in formatting date/numeric columns in SSRS matrix report

Mine is tablix report, with columns and values. Which are dynamically generating.
Issue is, there are some date and numeric columns which i want to format, and for that i am trying below given expressions:
=IIf(Fields!ColumnName.Value = "Charge",
FormatCurrency(Fields!Value.Value, 2),
IIf(Fields!ColumnName.Value = "StartDate",
FORMAT(CDate(Fields!Value.Value),"MM-dd-yyyy"),
IIf(Fields!ColumnName.Value = "EndDate",
FORMAT(CDate(Fields!Value.Value),"MM-dd-yyyy"),
Fields!Value.Value
)
)
)
OR
=Switch
(
Fields!ColumnName.Value = "Charge", FormatCurrency(Fields!Value.Value, 2),
Fields!ColumnName.Value = "StartDate", FORMAT(CDate(Fields!Value.Value),"MM-dd-yyyy"),
Fields!ColumnName.Value = "EndDate", FORMAT(CDate(Fields!Value.Value),"MM-dd-yyyy"),
true, Fields!Value.Value
)
OR
=IIF(IsNumeric(Fields!Value.Value), FormatNumber(Fields!Value.Value, 2), Fields!Value.Value)
none of them are working, it changes the number columns correctly and then it gives #Error in every columns.
Add the following custom code to your report
Public Function FormatColumn(columnName As String, value AS String) As String
Select columnName
Case "Charge"
Return Format(CLng(value), "c2")
Case "StartDate"
Return Format(CDate(value),"MM-dd-yyyy")
Case "EndDate"
Return Format(CDate(value),"MM-dd-yyyy")
Case Else
Return value
End Select
End Function
Set the cell expression to
= Code.FormatColumn(Fields!ColumnName.Value,Fields!value.Value)

How do I create a DAX expression to display a calculation from a derived table?

I'm using DaxStudio to test some measures, but am having trouble getting them to work. I can run the following expression, but don't know how to run an average of the field Mean to show just the mean of that. I'm basically expecting output to be a single cell with the average.
DAX Query:
EVALUATE
FILTER(
NATURALINNERJOIN(Alldata, NATURALINNERJOIN('Label', NATURALINNERJOIN('LabelBSkill', 'LabelCSkill'))),
'LabelCSkill'[Name] = "Critical"
&& 'Label'[Type]="Red"
)
Mean is in the table Alldata if that matters
Give this a try:
EVALUATE
ROW (
"Mean", CALCULATE (
AVERAGE ( Alldata[Mean] ),
'LabelCSkill'[Name] = "Critical",
'Label'[Type] = "Red"
)
)

How to store a list or a number into empty array in jsl?

I face a problem on how to store a list or a number into an empty array, below is my code :
For( i = 1, i <= N Items( S ), i++,
dt:Family Device << set name( "family device" );
dt << Select Where(Starts With( dt:family device, S[i] ) ) ;
baseDT = dt << Subset( output table name( "Subset" ), selected rows( 1 ), selected columns( 0 ), "invisible");
I plan to store baseDT in the empty array, Anyone has an idea on the store function? I very new to JSL if in python we will use append function to store, then how about jsl?
Initialize an empty array as
emp_array = {};
Append to array as :
Insert Into(emp_array, baseDT)
Then you can access the elements using index eg:
emp_array[n]

DAX HASONEVALUE row filter

12 Total :=
SWITCH (
TRUE (),
HASONEVALUE ([level04] ), CALCULATE (
[Local],
DATESINPERIOD (
Calendar[Date],
MAX ( Calendar[Date] ),
-12,
MONTH
)
),
HASONEVALUE ([level03]),If([level 03]= "calculation:" && [level03]= "Cash:" && [level03]= "Costs:"=>0, Blank(), CALCULATE (
[Local],
DATESINPERIOD (
Calendar[Date],
MAX ( Calendar[Date] ),
-12,
MONTH
)
)
),
HASONEVALUE ( [level02] ), BLANK ()
)
I would like to add condition that if lever 03 = cash, calculation, and cost then return blank to remove sub total rows. I tried something like that and its not working properly it gives me error "value for column level03 cannot be determined in the current context". how can i add that condition in level03 column?
Just a side note, "its not working properly" is tremendously unhelpful in determining the source of problems. Specifically in a Power Pivot/Tabular model, this link provides a list of ways to help answerers help you.
Syntactically, there are some errors. Let's address those and see if the behavior is appropriate before diving into alternate measure definitions.
This section is the problem:
...
,HASONEVALUE([level03])
// Note, you are inconsistent in referring to [level03] and
// [level 03]
,If( // Below you are testing column references against scalar
// literals. DAX doesn't understand how to do this, so you
// have to wrap each reference in a VALUES() function, which
// can be implicitly converted to a scalar value
[level 03] = 'calculation:' // DAX needs double quotes: ""
&& [level03]= 'Cash:' // You have multiple predicates
&& [level03]=' Costs:'=>0 // for a single field combined
// with a logical and - these
// can't all simultaneously be true
,Blank()
,CALCULATE(
[Local]
,DATESINPERIOD(
Calendar[Date],
MAX ( Calendar[Date] ),
-12,
MONTH
)
)
)
,....
I am just going to change the combination of predicates to a logical or in my rewrite, so that it's possible for this IF() to return a BLANK. The way it's written above, even fixing the syntax errors will cause it to always evaluate the else condition, because [level 03] cannot simultaneously have the value of "calculation:", "Cash:", and " Costs:=>0".
...
,HASONEVALUE('<table>'[level03])
// As a best practice, you should always use fully qualified
// column references - 'table'[field]
// Also, I've referred only to [level03] below
,IF( // Note we've wrapped [level 03] in VALUES() below - this will
// allow our comparisons to scalar literals
VALUES('<table>'[level03]) = "calculation:" // double quotes
|| VALUES('<table>'[level03]) = "Cash:"
// Note: we've changed the logical and, &&, to a logical
// or, || - meaning if any 1 of these predicates is true,
// we'll return BLANK
|| VALUES('<table>'[level03]) = " Costs:=>0"
,BLANK()
,CALCULATE(
[Local]
,DATESINPERIOD(
Calendar[Date]
,MAX( Calendar[Date] )
,-12
,MONTH
)
)
)
,....
What this will do is check for any cell on the pivot table where [level03] has exactly one distinct value - when this is true, it will evaluate the IF() function.
The IF() function will check the value of [level03]. If that value is any one of the three following values, "calculation:", "Cash:", or " Costs:=>0", it will return BLANK. If the value of [level03] is not any of those three, it will evaluate the CALCULATE(), which returns the measure [Local] for a rolling 12 month period.

Resources