I am trying to make a simple DAX query where if the value is more than 8 it should be consider as a 8
As an example
if value is 24 consider as 8
So whenever the value is 8 or more than 8, it should be 8.
How i can do that in a DAX query or in a POWER Query !
I have search a lot here ---
https://msdn.microsoft.com/en-us/library/ee634907.aspx
but did not find any solution !
Do anyone knows any solution to this problem !
Power Query
// Add new custom field
Max8 =
if [FieldName] > 8
then 8
else [FieldName]
DAX
// Calculated column
Max8 =
IF(
'TableName'[FieldName] > 8
,8
,'TableName'[FieldName]
)
// As a measure to test another measure's return value
Max8:=
IF(
[MeasureName] > 8
,8
,[MeasureName]
)
Use the two parameter version of the MIN function:
MIN('TableName'[FieldName], 8)
This gives you the smaller of 'TableName'[FieldName] and 8.
I solved a similar situation by using AND and Nested IF
RANK = IF(AND(STUDENT[SCORE] >= 50, STUDENT[SCORE] <=100),"One" , "Two")
Related
I'm new to Dax and I'm struggling to get the results I require with a running total.
I hope I've give you enough information below to help..
thank for any help and pointer in advance.
I'm trying to create an insurance triangle, I have 3 tables fact_transaction_claims_payments, dimension_development_Periods and reporting_upto_information
fact_transaction_claims_payments
dimension_development_Periods
reporting_upto_information
diagram view
I've managed to get my running total to work but only where there is a development period held in the fact table and not all the ones in between held in my development period dimension
Power Pivot Running Total
for example i'd expect development period 1 - 10 to total 0.00 and 13 to 18 to total 103,710
but i can seem to get these to appear in my pivot.
Running Total Dax Expression
RT_TotalAmount1:=VAR CurrentDevelopmentPeriod =
CALCULATE(
DATEDIFF(
IF(
MAX('fact_transaction_claims_payments'[cUWYear]) < 2011
, DATE(MAX('fact_transaction_claims_payments'[cUWYear]),1,1)
, DATE(MAX('fact_transaction_claims_payments'[cUWYear]),4,1)
)
,MAX('fact_transaction_claims_payments'[EndOfMonthDate])
,MONTH)
, 'dimension_development_Periods' ) +1
VAR MaxDevelopmentPeriod =
CALCULATE(
DATEDIFF(
IF(
MAX('fact_transaction_claims_payments'[cUWYear]) < 2011
, DATE(MAX('fact_transaction_claims_payments'[cUWYear]),1,1)
, DATE(MAX('fact_transaction_claims_payments'[cUWYear]),4,1)
)
,MAX('reporting_upto_information'[EndOfMonthDate])
,MONTH)
, 'dimension_development_Periods' ) +1
VAR RunningTotal =
CALCULATE (
SUM('fact_transaction_claims_payments'[TotalAmount])
,FILTER (
ALL ('fact_transaction_claims_payments')
,'fact_transaction_claims_payments'[DevelopmentMonthNumber] <= CurrentDevelopmentPeriod
)
)
RETURN
RunningTotal
I've tried adding the ALL('dimension_development_Periods') into the VAR DevelopmentPeriod
but this just puts the grand total against every development period.
I'm thinking I now need to use the RunningTotal to calculate against the Development Period Dimension filtered <= the max development period for the cUWYear but I'm not sure on how to implement this and I need some advice can anyone help.
I need to convert a DAX expression I'm using i PowerBI to MDX to use in Excel > Olap > Calculated Measure (or member?). I'm no developer and do not have full access to the database, but connect to it using analysis services.
This DAX measure is working. I want to the same logic in Excel as a calculated measure (or calculated member?). Running measure displays sales quantity where the products has a 1 in either FilterA, FilterB or FilterC.
CALCULATE(
[SalesQtn],
FILTER(
'Product',
'Product'[FilterA] = "1" || 'Product'[FilterB] = "1" || 'Product'[FilterC] = "1"
)
)
I'm 98% newbie in In DAX and 100% newbie in MDX. I've managed to do like below in Calculated Measure to filter using FilterA = "1", but I recon a function is needed for combination FilterB and C using OR operation
([Measures.[SalesQtn],
[Product].[FilterA].&[1])
Try the following:
SUM(
{
([Product].[FilterA].&[1], [Product].[FilterB].[All], [Product].[FilterC].[All]),
([Product].[FilterA].[All], [Product].[FilterB].&[1], [Product].[FilterC].[All]),
([Product].[FilterA].[All], [Product].[FilterB].[All], [Product].[FilterC].&[1])
},
[Measures].[SalesQtn]
)
Or if there are some rows where two FilterA and FilterB are 1 that might produce a wrong result. In that case try:
Sum(
Filter(
[Product].[FilterA].[FilterA].Members
* [Product].[FilterB].[FilterB].Members
* [Product].[FilterC].[FilterC].Members,
[Product].[FilterA].CurrentMember is [Product].[FilterA].&[1]
Or [Product].[FilterB].CurrentMember is [Product].[FilterB].&[2]
Or [Product].[FilterC].CurrentMember is [Product].[FilterC].&[1]
),
[Measures].[SalesQtn]
)
I have a custom calculation using the number of days.
<= 5 and my DAX calc is =[Total Days Aged]<=5
=6 and <=10 and my DAX calc is =([Total Days Aged]<=10)&&([Total Days Aged]>=6)
My calculation are above which are returning 'True' or 'False expressions. How can I calculate the total number of 'true' values in the column?
I've tried the following and the IF function, but I can't get it to work.
=calculate(DISTINCTCOUNT(Query[0-5 Days]), Query[0-5 Days] = "True")
=CALCULATE(DISTINCT(Query[0-5 Days]), Query[0-5 Days] = "True")
My error message is: "DAX comparison operations do not support comparing values type of true/false of values with type text."
Thanks in advance,
It looks like you are trying to compare a logical true/false with a string. You should try replacing the string "True" in the query with logical value TRUE(). Try the query below.
=CALCULATE(DISTINCT(Query[0-5 Days]), Query[0-5 Days] = TRUE() )
I've to calculate the différence between two Dates : TODAY() and DATE_DEB_VAC.
With Oracle, it's kinda easy : TODAY()-DATE_DEB_VAC -> give the number of day between those 2 date.
But I've to do it with in an ETL (GENIO). I've a column to stock it like that :
NUMBER_DAY_DIFF (NUMBER 10) = TODAY()-DATE_DEB_VAC. But it's impossible to stock it cause it's 2 date.
How can i do this ? :(
You can try the val function of GENIO ETL
VAL(TODAY()-DATE_DEB_VAC)
this is equivalent to to_numbre in Oracle
NUMBER_DAY_DIFF (NUMBER 10) = DATEDIFF (TODAY; DATE_DEB_VAC)
Should give you what you need.
I have a query which returns results for last 12 months, and I need to apply a filter in a way, that only product models with particular measure in last 7 months > 0 (at least in one of these months) are returned.
I could do it in this way:
SELECT {[Measures].[MQ]} ON COLUMNS,
FILTER([dim_ProductModel].[Product Model].members, (([Dim_Date].[Date Full].&[2013-08-01],[Measures].[MQ]) > 0) OR (([Dim_Date].[Date Full].&[2013-09-01],[Measures].[MQ]) > 0) OR ([Dim_Date].[Date Full].&[2013-10-01],[Measures].[MQ]) > 0) * {[Dim_Date].[Date Full].&[2013-08-01]:[Dim_Date].[Date Full].&[2014-02-01]} ON ROWS FROM [cub_dashboard_spares]
(I left other ORs conjuctions) So I would need 6 ORs which I dont like,
somehow it is not possible to write the filter it in this way as I would expect (pseudocode):
FILTER([dim_ProductModel].[Product Model].members, (ANY({[Dim_Date].[Date Full].&[2013-08-01]:[Dim_Date].[Date Full].&[2014-02-01]}),[Measures].[MQ]) > 0)
, is there please some trick/syntax how to avoid using mutliple ORs? Like ANY or idk..
thank you very much for help in advance,
You could use another Filter() and check if that has at least one result with Count:
FILTER([dim_ProductModel].[Product Model].members,
FILTER({[Dim_Date].[Date Full].&[2013-08-01]:[Dim_Date].[Date Full].&[2014-02-01]}),
[Measures].[MQ]) > 0
).Count > 0
)
Assuming there are no negative values of MQ, you can also observe that if at least one month has values > 0, then the sum must be > 0, and use
FILTER([dim_ProductModel].[Product Model].members,
Sum({[Dim_Date].[Date Full].&[2013-08-01]:[Dim_Date].[Date Full].&[2014-02-01]}),
[Measures].[MQ]
)
> 0
)